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-ast.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-ast.cc')
-rw-r--r-- | src/binary-reader-ast.cc | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/binary-reader-ast.cc b/src/binary-reader-ast.cc index 8763371d..2ab46655 100644 --- a/src/binary-reader-ast.cc +++ b/src/binary-reader-ast.cc @@ -51,7 +51,7 @@ struct Context { Expr** current_init_expr; }; -static void handle_error(Context* ctx, uint32_t offset, const char* message); +static bool handle_error(Context* ctx, uint32_t offset, const char* message); static void WABT_PRINTF_FORMAT(2, 3) print_error(Context* ctx, const char* format, ...) { @@ -117,16 +117,17 @@ static Result append_expr(Context* ctx, Expr* expr) { return Result::Ok; } -static void handle_error(Context* ctx, uint32_t offset, const char* message) { +static bool handle_error(Context* ctx, uint32_t offset, const char* message) { 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 on_error(BinaryReaderContext* reader_context, const char* message) { +static bool on_error(BinaryReaderContext* reader_context, const char* message) { Context* ctx = static_cast<Context*>(reader_context->user_data); - handle_error(ctx, reader_context->offset, message); + return handle_error(ctx, reader_context->offset, message); } static Result on_signature_count(uint32_t count, void* user_data) { |