diff options
-rw-r--r-- | CMakeLists.txt | 10 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | fuzz-in/wast.dict | 384 | ||||
-rwxr-xr-x | scripts/fuzz-wasm2wast.sh | 24 | ||||
-rwxr-xr-x | scripts/fuzz-wast2wasm.sh | 24 | ||||
-rw-r--r-- | src/binary-reader.cc | 2 | ||||
-rw-r--r-- | src/common.h | 13 | ||||
-rw-r--r-- | src/config.h.in | 2 | ||||
-rw-r--r-- | src/literal.cc | 4 | ||||
-rw-r--r-- | src/resolve-names.cc | 3 | ||||
-rw-r--r-- | src/tools/wasm-interp.cc | 8 | ||||
-rw-r--r-- | src/tools/wasm-link.cc | 8 | ||||
-rw-r--r-- | src/tools/wasm2wast.cc | 8 | ||||
-rw-r--r-- | src/tools/wasmdump.cc | 8 | ||||
-rw-r--r-- | src/tools/wasmopcodecnt.cc | 8 | ||||
-rw-r--r-- | src/tools/wast-desugar.cc | 8 | ||||
-rw-r--r-- | src/tools/wast2wasm.cc | 8 |
17 files changed, 328 insertions, 196 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3880b476..426f5893 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ option(USE_MSAN "Use memory sanitizer" OFF) option(USE_LSAN "Use leak sanitizer" OFF) option(USE_UBSAN "Use undefined behavior sanitizer" OFF) option(CODE_COVERAGE "Build with code coverage enabled" OFF) +option(WITH_EXCEPTIONS "Build with exceptions enabled" OFF) if (${CMAKE_C_COMPILER_ID} STREQUAL "Clang") set(COMPILER_IS_CLANG 1) @@ -86,6 +87,11 @@ if (COMPILER_IS_MSVC) # disable warnings C4267 and C4244: conversion/truncation from larger to smaller type. # disable warning C4800: implicit conversion from larger int to bool add_definitions(-W3 -wd4018 -wd4056 -wd4756 -wd4267 -wd4244 -wd4800 -WX -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS) + + if (NOT WITH_EXCEPTIONS) + # disable exception use in C++ library + add_definitions(-D_HAS_EXCEPTIONS=0) + endif () else () # disable -Wunused-parameter: this is really common when implementing # interfaces, etc. @@ -95,6 +101,10 @@ else () -Wold-style-cast ) + if (NOT WITH_EXCEPTIONS) + add_definitions(-fno-exceptions) + endif () + # Need to define __STDC_*_MACROS because C99 specifies that C++ shouldn't # define format (e.g. PRIu64) or limit (e.g. UINT32_MAX) macros without the # definition, and some libcs (e.g. glibc2.17 and earlier) follow that. @@ -54,7 +54,7 @@ NO_TESTS_DIR := no-tests/ GCC_FLAG := -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ GCC_I686_FLAG := -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ \ -DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32 -GCC_FUZZ_FLAG := -DCMAKE_C_COMPILER=${GCC_FUZZ_CC} -DCMAKE_CXX_COMPILER=${GCC_FUZZ_CXX} +GCC_FUZZ_FLAG := -DCMAKE_C_COMPILER=${GCC_FUZZ_CC} -DCMAKE_CXX_COMPILER=${GCC_FUZZ_CXX} -DWITH_EXCEPTIONS=ON CLANG_FLAG := -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ EMSCRIPTEN_FLAG := -DCMAKE_TOOLCHAIN_FILE=${EMSCRIPTEN_DIR}/cmake/Modules/Platform/Emscripten.cmake DEBUG_FLAG := -DCMAKE_BUILD_TYPE=Debug diff --git a/fuzz-in/wast.dict b/fuzz-in/wast.dict index 67022b7b..46403fe5 100644 --- a/fuzz-in/wast.dict +++ b/fuzz-in/wast.dict @@ -31,189 +31,201 @@ misc_float_inf="infinity" misc_float_nan="nan:0xf00baa" misc_float_sign="-6.02e-23" -op_nop="(nop" -op_block="(block" -op_if="(if" -op_if_else="(if_else" -op_loop="(loop" -op_br="(br" -op_br_if="(br_if" -op_tableswitch="(tableswitch" -op_call="(call" -op_call_import="(call_import" -op_call_indirect="(call_indirect" -op_case="(case" -op_return="(return" -op_get_local="(get_local" -op_set_local="(set_local" -op_i32_load="(i32.load" -op_i64_load="(i64.load" -op_f32_load="(f32.load" -op_f64_load="(f64.load" -op_i32_store="(i32.store" -op_i64_store="(i64.store" -op_f32_store="(f32.store" -op_f64_store="(f64.store" -op_i32_load8_s="(i32.load8_s" -op_i64_load8_s="(i64.load8_s" -op_i32_load8_u="(i32.load8_u" -op_i64_load8_u="(i64.load8_u" -op_i32_load16_s="(i32.load16_s" -op_i64_load16_s="(i64.load16_s" -op_i32_load16_u="(i32.load16_u" -op_i64_load16_u="(i64.load16_u" -op_i64_load32_s="(i64.load32_s" -op_i64_load32_u="(i64.load32_u" -op_i32_store8="(i32.store8" -op_i64_store8="(i64.store8" -op_i32_store16="(i32.store16" -op_i64_store16="(i64.store16" -op_i64_store32="(i64.store32" -op_i32_const="(i32.const" -op_i64_const="(i64.const" -op_f32_const="(f32.const" -op_f64_const="(f64.const" -op_i32_not="(i32.not" -op_i32_clz="(i32.clz" -op_i64_clz="(i64.clz" -op_i32_ctz="(i32.ctz" -op_i64_ctz="(i64.ctz" -op_i32_popcnt="(i32.popcnt" -op_i64_popcnt="(i64.popcnt" -op_f32_neg="(f32.neg" -op_f64_neg="(f64.neg" -op_f32_abs="(f32.abs" -op_f64_abs="(f64.abs" -op_f32_sqrt="(f32.sqrt" -op_f64_sqrt="(f64.sqrt" -op_f32_ceil="(f32.ceil" -op_f64_ceil="(f64.ceil" -op_f32_floor="(f32.floor" -op_f64_floor="(f64.floor" -op_f32_trunc="(f32.trunc" -op_f64_trunc="(f64.trunc" -op_f32_nearest="(f32.nearest" -op_f64_nearest="(f64.nearest" -op_i32_add="(i32.add" -op_i64_add="(i64.add" -op_i32_sub="(i32.sub" -op_i64_sub="(i64.sub" -op_i32_mul="(i32.mul" -op_i64_mul="(i64.mul" -op_i32_div_s="(i32.div_s" -op_i64_div_s="(i64.div_s" -op_i32_div_u="(i32.div_u" -op_i64_div_u="(i64.div_u" -op_i32_rem_s="(i32.rem_s" -op_i64_rem_s="(i64.rem_s" -op_i32_rem_u="(i32.rem_u" -op_i64_rem_u="(i64.rem_u" -op_i32_and="(i32.and" -op_i64_and="(i64.and" -op_i32_or="(i32.or" -op_i64_or="(i64.or" -op_i32_xor="(i32.xor" -op_i64_xor="(i64.xor" -op_i32_shl="(i32.shl" -op_i64_shl="(i64.shl" -op_i32_shr_s="(i32.shr_s" -op_i64_shr_s="(i64.shr_s" -op_i32_shr_u="(i32.shr_u" -op_i64_shr_u="(i64.shr_u" -op_i32_rotl="(i32.rotl" -op_i64_rotl="(i64.rotl" -op_f32_add="(f32.add" -op_f64_add="(f64.add" -op_f32_sub="(f32.sub" -op_f64_sub="(f64.sub" -op_f32_mul="(f32.mul" -op_f64_mul="(f64.mul" -op_f32_div="(f32.div" -op_f64_div="(f64.div" -op_f32_min="(f32.min" -op_f64_min="(f64.min" -op_f32_max="(f32.max" -op_f64_max="(f64.max" -op_f32_copysign="(f32.copysign" -op_f64_copysign="(f64.copysign" -op_i32_eq="(i32.eq" -op_i64_eq="(i64.eq" -op_i32_ne="(i32.ne" -op_i64_ne="(i64.ne" -op_i32_lt_s="(i32.lt_s" -op_i64_lt_s="(i64.lt_s" -op_i32_lt_u="(i32.lt_u" -op_i64_lt_u="(i64.lt_u" -op_i32_le_s="(i32.le_s" -op_i64_le_s="(i64.le_s" -op_i32_le_u="(i32.le_u" -op_i64_le_u="(i64.le_u" -op_i32_gt_s="(i32.gt_s" -op_i64_gt_s="(i64.gt_s" -op_i32_gt_u="(i32.gt_u" -op_i64_gt_u="(i64.gt_u" -op_i32_ge_s="(i32.ge_s" -op_i64_ge_s="(i64.ge_s" -op_i32_ge_u="(i32.ge_u" -op_i64_ge_u="(i64.ge_u" -op_f32_eq="(f32.eq" -op_f64_eq="(f64.eq" -op_f32_ne="(f32.ne" -op_f64_ne="(f64.ne" -op_f32_lt="(f32.lt" -op_f64_lt="(f64.lt" -op_f32_le="(f32.le" -op_f64_le="(f64.le" -op_f32_gt="(f32.gt" -op_f64_gt="(f64.gt" -op_f32_ge="(f32.ge" -op_f64_ge="(f64.ge" -op_i64_extend_s_i32="(i64.extend_s/i32" -op_i64_extend_u_i32="(i64.extend_u/i32" -op_i32_wrap_i64="(i32.wrap/i64" -op_i32_trunc_s_f32="(i32.trunc_s/f32" -op_i64_trunc_s_f32="(i64.trunc_s/f32" -op_i32_trunc_s_f64="(i32.trunc_s/f64" -op_i64_trunc_s_f64="(i64.trunc_s/f64" -op_i32_trunc_u_f32="(i32.trunc_u/f32" -op_i64_trunc_u_f32="(i64.trunc_u/f32" -op_i32_trunc_u_f64="(i32.trunc_u/f64" -op_i64_trunc_u_f64="(i64.trunc_u/f64" -op_f32_convert_s_i32="(f32.convert_s/i32" -op_f64_convert_s_i32="(f64.convert_s/i32" -op_f32_convert_s_i64="(f32.convert_s/i64" -op_f64_convert_s_i64="(f64.convert_s/i64" -op_f32_convert_u_i32="(f32.convert_u/i32" -op_f64_convert_u_i32="(f64.convert_u/i32" -op_f32_convert_u_i64="(f32.convert_u/i64" -op_f64_convert_u_i64="(f64.convert_u/i64" -op_f64_promote_f32="(f64.promote/f32" -op_f32_demote_f64="(f32.demote/f64" -op_f32_reinterpret_i32="(f32.reinterpret/i32" -op_i32_reinterpret_f32="(i32.reinterpret/f32" -op_f64_reinterpret_i64="(f64.reinterpret/i64" -op_i64_reinterpret_f64="(i64.reinterpret/f64" -op_i32_select="(i32.select" -op_i64_select="(i64.select" -op_f32_select="(f32.select" -op_f64_select="(f64.select" -op_unreachable="(unreachable" -op_memory_size="(memory_size" -op_grow_memory="(grow_memory" -op_type="(type" -op_func="(func" -op_param="(param" -op_result="(result" -op_local="(local" -op_module="(module" -op_memory="(memory" -op_segment="(segment" -op_import="(import" -op_export="(export" -op_table="(start" -op_table="(table" -op_assert_invalid="(assert_invalid" -op_assert_return="(assert_return" -op_assert_return_nan="(assert_return_nan" -op_assert_trap="(assert_trap" -op_invoke="(invoke" +op_nop="nop" +op_block="block" +op_if="if" +op_then="then" +op_else="else" +op_loop="loop" +op_br="br" +op_br_if="br_if" +op_br_table="br_table" +op_call="call" +op_call_indirect="call_indirect" +op_drop="drop" +op_end="end" +op_return="return" +op_get_local="get_local" +op_set_local="set_local" +op_tee_local="tee_local" +op_get_global="get_global" +op_set_global="set_global" +op_i32_load="i32.load" +op_i64_load="i64.load" +op_f32_load="f32.load" +op_f64_load="f64.load" +op_i32_store="i32.store" +op_i64_store="i64.store" +op_f32_store="f32.store" +op_f64_store="f64.store" +op_i32_load8_s="i32.load8_s" +op_i64_load8_s="i64.load8_s" +op_i32_load8_u="i32.load8_u" +op_i64_load8_u="i64.load8_u" +op_i32_load16_s="i32.load16_s" +op_i64_load16_s="i64.load16_s" +op_i32_load16_u="i32.load16_u" +op_i64_load16_u="i64.load16_u" +op_i64_load32_s="i64.load32_s" +op_i64_load32_u="i64.load32_u" +op_i32_store8="i32.store8" +op_i64_store8="i64.store8" +op_i32_store16="i32.store16" +op_i64_store16="i64.store16" +op_i64_store32="i64.store32" +op_i32_const="i32.const" +op_i64_const="i64.const" +op_f32_const="f32.const" +op_f64_const="f64.const" +op_i32_eqz="i32.eqz" +op_i64_eqz="i64.eqz" +op_i32_clz="i32.clz" +op_i64_clz="i64.clz" +op_i32_ctz="i32.ctz" +op_i64_ctz="i64.ctz" +op_i32_popcnt="i32.popcnt" +op_i64_popcnt="i64.popcnt" +op_f32_neg="f32.neg" +op_f64_neg="f64.neg" +op_f32_abs="f32.abs" +op_f64_abs="f64.abs" +op_f32_sqrt="f32.sqrt" +op_f64_sqrt="f64.sqrt" +op_f32_ceil="f32.ceil" +op_f64_ceil="f64.ceil" +op_f32_floor="f32.floor" +op_f64_floor="f64.floor" +op_f32_trunc="f32.trunc" +op_f64_trunc="f64.trunc" +op_f32_nearest="f32.nearest" +op_f64_nearest="f64.nearest" +op_i32_add="i32.add" +op_i64_add="i64.add" +op_i32_sub="i32.sub" +op_i64_sub="i64.sub" +op_i32_mul="i32.mul" +op_i64_mul="i64.mul" +op_i32_div_s="i32.div_s" +op_i64_div_s="i64.div_s" +op_i32_div_u="i32.div_u" +op_i64_div_u="i64.div_u" +op_i32_rem_s="i32.rem_s" +op_i64_rem_s="i64.rem_s" +op_i32_rem_u="i32.rem_u" +op_i64_rem_u="i64.rem_u" +op_i32_and="i32.and" +op_i64_and="i64.and" +op_i32_or="i32.or" +op_i64_or="i64.or" +op_i32_xor="i32.xor" +op_i64_xor="i64.xor" +op_i32_shl="i32.shl" +op_i64_shl="i64.shl" +op_i32_shr_s="i32.shr_s" +op_i64_shr_s="i64.shr_s" +op_i32_shr_u="i32.shr_u" +op_i64_shr_u="i64.shr_u" +op_i32_rotl="i32.rotl" +op_i64_rotl="i64.rotl" +op_f32_add="f32.add" +op_f64_add="f64.add" +op_f32_sub="f32.sub" +op_f64_sub="f64.sub" +op_f32_mul="f32.mul" +op_f64_mul="f64.mul" +op_f32_div="f32.div" +op_f64_div="f64.div" +op_f32_min="f32.min" +op_f64_min="f64.min" +op_f32_max="f32.max" +op_f64_max="f64.max" +op_f32_copysign="f32.copysign" +op_f64_copysign="f64.copysign" +op_i32_eq="i32.eq" +op_i64_eq="i64.eq" +op_i32_ne="i32.ne" +op_i64_ne="i64.ne" +op_i32_lt_s="i32.lt_s" +op_i64_lt_s="i64.lt_s" +op_i32_lt_u="i32.lt_u" +op_i64_lt_u="i64.lt_u" +op_i32_le_s="i32.le_s" +op_i64_le_s="i64.le_s" +op_i32_le_u="i32.le_u" +op_i64_le_u="i64.le_u" +op_i32_gt_s="i32.gt_s" +op_i64_gt_s="i64.gt_s" +op_i32_gt_u="i32.gt_u" +op_i64_gt_u="i64.gt_u" +op_i32_ge_s="i32.ge_s" +op_i64_ge_s="i64.ge_s" +op_i32_ge_u="i32.ge_u" +op_i64_ge_u="i64.ge_u" +op_f32_eq="f32.eq" +op_f64_eq="f64.eq" +op_f32_ne="f32.ne" +op_f64_ne="f64.ne" +op_f32_lt="f32.lt" +op_f64_lt="f64.lt" +op_f32_le="f32.le" +op_f64_le="f64.le" +op_f32_gt="f32.gt" +op_f64_gt="f64.gt" +op_f32_ge="f32.ge" +op_f64_ge="f64.ge" +op_i64_extend_s_i32="i64.extend_s/i32" +op_i64_extend_u_i32="i64.extend_u/i32" +op_i32_wrap_i64="i32.wrap/i64" +op_i32_trunc_s_f32="i32.trunc_s/f32" +op_i64_trunc_s_f32="i64.trunc_s/f32" +op_i32_trunc_s_f64="i32.trunc_s/f64" +op_i64_trunc_s_f64="i64.trunc_s/f64" +op_i32_trunc_u_f32="i32.trunc_u/f32" +op_i64_trunc_u_f32="i64.trunc_u/f32" +op_i32_trunc_u_f64="i32.trunc_u/f64" +op_i64_trunc_u_f64="i64.trunc_u/f64" +op_f32_convert_s_i32="f32.convert_s/i32" +op_f64_convert_s_i32="f64.convert_s/i32" +op_f32_convert_s_i64="f32.convert_s/i64" +op_f64_convert_s_i64="f64.convert_s/i64" +op_f32_convert_u_i32="f32.convert_u/i32" +op_f64_convert_u_i32="f64.convert_u/i32" +op_f32_convert_u_i64="f32.convert_u/i64" +op_f64_convert_u_i64="f64.convert_u/i64" +op_f64_promote_f32="f64.promote/f32" +op_f32_demote_f64="f32.demote/f64" +op_f32_reinterpret_i32="f32.reinterpret/i32" +op_i32_reinterpret_f32="i32.reinterpret/f32" +op_f64_reinterpret_i64="f64.reinterpret/i64" +op_i64_reinterpret_f64="i64.reinterpret/f64" +op_select="select" +op_unreachable="unreachable" +op_memory_size="current_memory" +op_grow_memory="grow_memory" +op_type="type" +op_func="func" +op_param="param" +op_result="result" +op_local="local" +op_global="global" +op_module="module" +op_table="table" +op_memory="memory" +op_table="start" +op_elem="elem" +op_data="data" +op_offset="offset" +op_align="align=" +op_import="import" +op_export="export" +op_register="register" +op_invoke="invoke" +op_get="get" +op_assert_malformed="assert_malformed" +op_assert_invalid="assert_invalid" +op_assert_unlinkable="assert_unlinkable" +op_assert_return="assert_return" +op_assert_return_canonical_nan="assert_return_canonical_nan" +op_assert_return_arithmetic_nan="assert_return_arithmetic_nan" +op_assert_trap="assert_trap" +op_assert_exhaustion="assert_exhaustion" diff --git a/scripts/fuzz-wasm2wast.sh b/scripts/fuzz-wasm2wast.sh new file mode 100755 index 00000000..8cfbca3b --- /dev/null +++ b/scripts/fuzz-wasm2wast.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# +# Copyright 2016 WebAssembly Community Group participants +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +set -o nounset +set -o errexit + +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" +ROOT_DIR="$(dirname "${SCRIPT_DIR}")" + +${FUZZ_BIN_DIR}/afl-fuzz -i fuzz-in/wasm/ -o fuzz-out -- out/gcc-fuzz/Debug/wasm2wast @@ diff --git a/scripts/fuzz-wast2wasm.sh b/scripts/fuzz-wast2wasm.sh new file mode 100755 index 00000000..d77321f8 --- /dev/null +++ b/scripts/fuzz-wast2wasm.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# +# Copyright 2016 WebAssembly Community Group participants +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +set -o nounset +set -o errexit + +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" +ROOT_DIR="$(dirname "${SCRIPT_DIR}")" + +${FUZZ_BIN_DIR}/afl-fuzz -x fuzz-in/wast.dict -i fuzz-in/wast/ -o fuzz-out -- out/gcc-fuzz/Debug/wast2wasm @@ diff --git a/src/binary-reader.cc b/src/binary-reader.cc index 778c1ed6..4425f6ea 100644 --- a/src/binary-reader.cc +++ b/src/binary-reader.cc @@ -950,6 +950,8 @@ static void read_names_section(Context* ctx, uint32_t section_size) { for (uint32_t j = 0; j < num_funcs; ++j) { uint32_t function_index; in_u32_leb128(ctx, &function_index, "function index"); + RAISE_ERROR_UNLESS(function_index < num_total_funcs(ctx), + "invalid function index: %u", function_index); uint32_t num_locals; in_u32_leb128(ctx, &num_locals, "local count"); CALLBACK(OnLocalNameLocalCount, function_index, num_locals); diff --git a/src/common.h b/src/common.h index 40be6e34..152800bd 100644 --- a/src/common.h +++ b/src/common.h @@ -73,6 +73,19 @@ type(const type&) = delete; \ type& operator=(const type&) = delete; +#if WITH_EXCEPTIONS +#define WABT_TRY try { +#define WABT_CATCH_BAD_ALLOC_AND_EXIT \ + } \ + catch (std::bad_alloc&) { \ + WABT_FATAL("Memory allocation failure.\n"); \ + } +#else +#define WABT_TRY +#define WABT_CATCH_BAD_ALLOC_AND_EXIT +#endif + + namespace wabt { enum class Result { diff --git a/src/config.h.in b/src/config.h.in index d3101eb4..b2dc04b4 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -41,6 +41,8 @@ #cmakedefine01 COMPILER_IS_GNU #cmakedefine01 COMPILER_IS_MSVC +#cmakedefine01 WITH_EXCEPTIONS + #define SIZEOF_SIZE_T @SIZEOF_SIZE_T@ #define SIZEOF_INT @SIZEOF_INT@ #define SIZEOF_LONG @SIZEOF_LONG@ diff --git a/src/literal.cc b/src/literal.cc index 75efa1fe..8e025ace 100644 --- a/src/literal.cc +++ b/src/literal.cc @@ -376,7 +376,7 @@ static void parse_float_infinity(const char* s, } else if (*s == '+') { s++; } - assert(string_starts_with(s, end, "infinity")); + assert(string_starts_with(s, end, "inf")); // Could be inf or infinity. *out_bits = make_float(is_neg, F32_MAX_EXP, 0); } @@ -716,7 +716,7 @@ static void parse_double_infinity(const char* s, } else if (*s == '+') { s++; } - assert(string_starts_with(s, end, "infinity")); + assert(string_starts_with(s, end, "inf")); // Could be inf or infinity. *out_bits = make_double(is_neg, F64_MAX_EXP, 0); } diff --git a/src/resolve-names.cc b/src/resolve-names.cc index f68c4ee4..fb823c5c 100644 --- a/src/resolve-names.cc +++ b/src/resolve-names.cc @@ -150,6 +150,9 @@ static void resolve_memory_var(Context* ctx, Var* var) { static void resolve_local_var(Context* ctx, Var* var) { if (var->type == VarType::Name) { + if (!ctx->current_func) + return; + int index = get_local_index_by_var(ctx->current_func, var); if (index == -1) { print_error(ctx, &var->loc, diff --git a/src/tools/wasm-interp.cc b/src/tools/wasm-interp.cc index 44bb1e25..a4da13f8 100644 --- a/src/tools/wasm-interp.cc +++ b/src/tools/wasm-interp.cc @@ -1618,7 +1618,7 @@ static Result read_and_run_spec_json(const char* spec_json_filename) { return result; } -int main(int argc, char** argv) { +int ProgramMain(int argc, char** argv) { init_stdio(); parse_options(argc, argv); @@ -1632,3 +1632,9 @@ int main(int argc, char** argv) { } return result != Result::Ok; } + +int main(int argc, char** argv) { + WABT_TRY + return ProgramMain(argc, argv); + WABT_CATCH_BAD_ALLOC_AND_EXIT +} diff --git a/src/tools/wasm-link.cc b/src/tools/wasm-link.cc index 7ecfb71d..d21e586f 100644 --- a/src/tools/wasm-link.cc +++ b/src/tools/wasm-link.cc @@ -829,7 +829,7 @@ static Result perform_link(Context* ctx) { return Result::Ok; } -int main(int argc, char** argv) { +int ProgramMain(int argc, char** argv) { init_stdio(); Context context; @@ -860,3 +860,9 @@ int main(int argc, char** argv) { result = perform_link(&context); return result != Result::Ok; } + +int main(int argc, char** argv) { + WABT_TRY + return ProgramMain(argc, argv); + WABT_CATCH_BAD_ALLOC_AND_EXIT +} diff --git a/src/tools/wasm2wast.cc b/src/tools/wasm2wast.cc index 7f3ef1d1..94dd3fa8 100644 --- a/src/tools/wasm2wast.cc +++ b/src/tools/wasm2wast.cc @@ -131,7 +131,7 @@ static void parse_options(int argc, char** argv) { } } -int main(int argc, char** argv) { +int ProgramMain(int argc, char** argv) { Result result; init_stdio(); @@ -166,3 +166,9 @@ int main(int argc, char** argv) { } return result != Result::Ok; } + +int main(int argc, char** argv) { + WABT_TRY + return ProgramMain(argc, argv); + WABT_CATCH_BAD_ALLOC_AND_EXIT +} diff --git a/src/tools/wasmdump.cc b/src/tools/wasmdump.cc index fc1b3cd6..37651277 100644 --- a/src/tools/wasmdump.cc +++ b/src/tools/wasmdump.cc @@ -194,7 +194,7 @@ done: return result; } -int main(int argc, char** argv) { +int ProgramMain(int argc, char** argv) { init_stdio(); parse_options(argc, argv); @@ -216,3 +216,9 @@ int main(int argc, char** argv) { return 0; } + +int main(int argc, char** argv) { + WABT_TRY + return ProgramMain(argc, argv); + WABT_CATCH_BAD_ALLOC_AND_EXIT +} diff --git a/src/tools/wasmopcodecnt.cc b/src/tools/wasmopcodecnt.cc index b99051bb..49c1c822 100644 --- a/src/tools/wasmopcodecnt.cc +++ b/src/tools/wasmopcodecnt.cc @@ -284,7 +284,7 @@ static void display_sorted_int_pair_counter_vector( display_second_fcn, opcode_name); } -int main(int argc, char** argv) { +int ProgramMain(int argc, char** argv) { init_stdio(); parse_options(argc, argv); @@ -333,3 +333,9 @@ int main(int argc, char** argv) { delete[] data; return result != Result::Ok; } + +int main(int argc, char** argv) { + WABT_TRY + return ProgramMain(argc, argv); + WABT_CATCH_BAD_ALLOC_AND_EXIT +} diff --git a/src/tools/wast-desugar.cc b/src/tools/wast-desugar.cc index 0642d682..b1418e6c 100644 --- a/src/tools/wast-desugar.cc +++ b/src/tools/wast-desugar.cc @@ -124,7 +124,7 @@ struct Context { Result result; }; -int main(int argc, char** argv) { +int ProgramMain(int argc, char** argv) { init_stdio(); parse_options(argc, argv); @@ -157,3 +157,9 @@ int main(int argc, char** argv) { delete script; return result != Result::Ok; } + +int main(int argc, char** argv) { + WABT_TRY + return ProgramMain(argc, argv); + WABT_CATCH_BAD_ALLOC_AND_EXIT +} diff --git a/src/tools/wast2wasm.cc b/src/tools/wast2wasm.cc index 9ab56afe..9296dd5e 100644 --- a/src/tools/wast2wasm.cc +++ b/src/tools/wast2wasm.cc @@ -193,7 +193,7 @@ static void write_buffer_to_file(const char* filename, } } -int main(int argc, char** argv) { +int ProgramMain(int argc, char** argv) { init_stdio(); parse_options(argc, argv); @@ -239,3 +239,9 @@ int main(int argc, char** argv) { delete script; return result != Result::Ok; } + +int main(int argc, char** argv) { + WABT_TRY + return ProgramMain(argc, argv); + WABT_CATCH_BAD_ALLOC_AND_EXIT +} |