From bc307c19ddca4bef900db3ff9d512bd21a57be60 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 9 May 2016 11:02:43 -0700 Subject: allow error handling in binary parsing --- src/wasm-binary.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/wasm-binary.h') diff --git a/src/wasm-binary.h b/src/wasm-binary.h index c889f1418..4670c9de3 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1164,13 +1164,14 @@ class WasmBinaryBuilder { Module& wasm; MixedArena& allocator; std::vector& input; + std::function onError; bool debug; size_t pos = 0; int32_t startIndex = -1; public: - WasmBinaryBuilder(Module& wasm, std::vector& input, bool debug) : wasm(wasm), allocator(wasm.allocator), input(input), debug(debug) {} + WasmBinaryBuilder(Module& wasm, std::vector& input, std::function onError, bool debug) : wasm(wasm), allocator(wasm.allocator), input(input), onError(onError), debug(debug) {} void read() { -- cgit v1.2.3 From b519fd87f7f1e1adead0ed648f29301303518ff0 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 9 May 2016 11:07:28 -0700 Subject: add error handling for binary errors in new spec test --- src/wasm-binary.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/wasm-binary.h') diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 4670c9de3..a5cf0fe5c 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1226,7 +1226,7 @@ public: } uint8_t getInt8() { - assert(more()); + if (!more()) onError(); if (debug) std::cerr << "getInt8: " << (int)(uint8_t)input[pos] << " (at " << pos << ")" << std::endl; return input[pos++]; } @@ -1330,27 +1330,27 @@ public: void verifyInt8(int8_t x) { int8_t y = getInt8(); - assert(x == y); + if (x != y) onError(); } void verifyInt16(int16_t x) { int16_t y = getInt16(); - assert(x == y); + if (x != y) onError(); } void verifyInt32(int32_t x) { int32_t y = getInt32(); - assert(x == y); + if (x != y) onError(); } void verifyInt64(int64_t x) { int64_t y = getInt64(); - assert(x == y); + if (x != y) onError(); } void verifyFloat32(float x) { float y = getFloat32(); - assert(x == y); + if (x != y) onError(); } void verifyFloat64(double x) { double y = getFloat64(); - assert(x == y); + if (x != y) onError(); } void ungetInt8() { -- cgit v1.2.3