Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate scanner: more informative error messages #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions pire/scanners/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <stdlib.h>
#include "../align.h"
#include "../stub/defaults.h"
#include "../stub/lexical_cast.h"
#include "../defs.h"
#include "../platform.h"

Expand Down Expand Up @@ -53,12 +54,34 @@ namespace Pire {

void Validate(ui32 type, size_t hdrsize) const
{
if (Magic != MAGIC || PtrSize != sizeof(void*) || MaxWordSize != sizeof(Impl::MaxSizeWord))
throw Error("Serialized regexp incompatible with your system");
// fix link errors:
// ./.libs/libpire.so: undefined reference to `Pire::Header::MAGIC'
ui32 MAGIC_ = MAGIC;
ui32 RE_VERSION_ = RE_VERSION;
if (Magic != MAGIC)
throw Error("Bad Magic in serialized regexp. "
"Expected: " + ToString(MAGIC_) + ". "
"Found: " + ToString(Magic));
if (PtrSize != sizeof(void*))
throw Error("Bad PtrSize in serialized regexp. "
"Expected: " + ToString(sizeof(void*)) + ". "
"Found: " + ToString(PtrSize));
if (MaxWordSize != sizeof(Impl::MaxSizeWord))
throw Error("Bad MaxWordSize in serialized regexp. "
"Expected: " + ToString(sizeof(Impl::MaxSizeWord)) + ". "
"Found: " + ToString(MaxWordSize));
if (Version != RE_VERSION)
throw Error("You are trying to used an incompatible version of a serialized regexp");
if ((type != 0 && type != Type) || (hdrsize != 0 && HdrSize != hdrsize))
throw Error("Serialized regexp incompatible with your system");
throw Error("Bad Version in serialized regexp. "
"Expected: " + ToString(RE_VERSION_) + ". "
"Found: " + ToString(Version));
if (type != 0 && type != Type)
throw Error("Bad type in serialized regexp. "
"Expected: " + ToString(type) + ". "
"Found: " + ToString(Type));
if (hdrsize != 0 && HdrSize != hdrsize)
throw Error("Bad HdrSize in serialized regexp. "
"Expected: " + ToString(hdrsize) + ". "
"Found: " + ToString(HdrSize));
}
};

Expand Down