diff options
author | Ben Smith <binjimin@gmail.com> | 2017-03-13 16:32:11 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-13 16:32:11 -0700 |
commit | a02beb8e12b21f63dcfbf862366d3e44f4eb62d3 (patch) | |
tree | 64833025e93a154d7166dfbcddf04fcfea85ce03 /src/binary-reader-interpreter.cc | |
parent | a17662511d4e7c277f5add3b61453e7b708b2756 (diff) | |
download | wabt-a02beb8e12b21f63dcfbf862366d3e44f4eb62d3.tar.gz wabt-a02beb8e12b21f63dcfbf862366d3e44f4eb62d3.tar.bz2 wabt-a02beb8e12b21f63dcfbf862366d3e44f4eb62d3.zip |
Fix crash using binary reader logging with error (#351)
When the binary logging is turned on, it can't use the
`reader->on_error` directly since that function expects that the
user_data is the BinaryReaderInterpreter context (for example), but it
is actually the LoggingContext.
To make it easier for users to use the default error handler, now they
return a bool saying whether the error was handled.
Some additional changes:
* Add a test that uses logging and succeeds
* Add a test that uses logging and has an error
* Change the `run-*-interp.py` scripts to use `-t` for tracing and `-v`
for logging
Diffstat (limited to 'src/binary-reader-interpreter.cc')
-rw-r--r-- | src/binary-reader-interpreter.cc | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/binary-reader-interpreter.cc b/src/binary-reader-interpreter.cc index 52642b44..a9a3f937 100644 --- a/src/binary-reader-interpreter.cc +++ b/src/binary-reader-interpreter.cc @@ -103,11 +103,12 @@ static Label* top_label(Context* ctx) { return get_label(ctx, 0); } -static void handle_error(uint32_t offset, const char* message, Context* ctx) { +static bool handle_error(uint32_t offset, const char* message, Context* ctx) { if (ctx->error_handler->on_error) { - ctx->error_handler->on_error(offset, message, - ctx->error_handler->user_data); + return ctx->error_handler->on_error(offset, message, + ctx->error_handler->user_data); } + return false; } static void WABT_PRINTF_FORMAT(2, 3) @@ -344,8 +345,9 @@ static Result emit_func_offset(Context* ctx, return Result::Ok; } -static void on_error(BinaryReaderContext* ctx, const char* message) { - handle_error(ctx->offset, message, static_cast<Context*>(ctx->user_data)); +static bool on_error(BinaryReaderContext* ctx, const char* message) { + return handle_error(ctx->offset, message, + static_cast<Context*>(ctx->user_data)); } static Result on_signature_count(uint32_t count, void* user_data) { |