diff options
author | Ben Smith <binjimin@gmail.com> | 2018-02-15 19:23:15 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-15 19:23:15 -0800 |
commit | 7b196f2f743d05f56dfec2b8f005e3f74b8ad2bc (patch) | |
tree | 8a146b2c35d31171a853de3c50cf76756d4fc93f /src/binary-reader-ir.cc | |
parent | d77796e39c0fc15a2710faa76fea126bec40b206 (diff) | |
download | wabt-7b196f2f743d05f56dfec2b8f005e3f74b8ad2bc.tar.gz wabt-7b196f2f743d05f56dfec2b8f005e3f74b8ad2bc.tar.bz2 wabt-7b196f2f743d05f56dfec2b8f005e3f74b8ad2bc.zip |
Add try/catch around calls to reserve (#761)
Only when exceptions are enabled via the CMake `WITH_EXCEPTIONS` option.
Diffstat (limited to 'src/binary-reader-ir.cc')
-rw-r--r-- | src/binary-reader-ir.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/binary-reader-ir.cc b/src/binary-reader-ir.cc index bd48f51d..7d9c301f 100644 --- a/src/binary-reader-ir.cc +++ b/src/binary-reader-ir.cc @@ -302,7 +302,9 @@ bool BinaryReaderIR::OnError(const char* message) { } Result BinaryReaderIR::OnTypeCount(Index count) { + WABT_TRY module_->func_types.reserve(count); + WABT_CATCH_BAD_ALLOC return Result::Ok; } @@ -320,7 +322,9 @@ Result BinaryReaderIR::OnType(Index index, } Result BinaryReaderIR::OnImportCount(Index count) { + WABT_TRY module_->imports.reserve(count); + WABT_CATCH_BAD_ALLOC return Result::Ok; } @@ -400,7 +404,9 @@ Result BinaryReaderIR::OnImportException(Index import_index, } Result BinaryReaderIR::OnFunctionCount(Index count) { + WABT_TRY module_->funcs.reserve(module_->num_func_imports + count); + WABT_CATCH_BAD_ALLOC return Result::Ok; } @@ -415,7 +421,9 @@ Result BinaryReaderIR::OnFunction(Index index, Index sig_index) { } Result BinaryReaderIR::OnTableCount(Index count) { + WABT_TRY module_->tables.reserve(module_->num_table_imports + count); + WABT_CATCH_BAD_ALLOC return Result::Ok; } @@ -430,7 +438,9 @@ Result BinaryReaderIR::OnTable(Index index, } Result BinaryReaderIR::OnMemoryCount(Index count) { + WABT_TRY module_->memories.reserve(module_->num_memory_imports + count); + WABT_CATCH_BAD_ALLOC return Result::Ok; } @@ -443,7 +453,9 @@ Result BinaryReaderIR::OnMemory(Index index, const Limits* page_limits) { } Result BinaryReaderIR::OnGlobalCount(Index count) { + WABT_TRY module_->globals.reserve(module_->num_global_imports + count); + WABT_CATCH_BAD_ALLOC return Result::Ok; } @@ -469,7 +481,9 @@ Result BinaryReaderIR::EndGlobalInitExpr(Index index) { } Result BinaryReaderIR::OnExportCount(Index count) { + WABT_TRY module_->exports.reserve(count); + WABT_CATCH_BAD_ALLOC return Result::Ok; } @@ -523,7 +537,9 @@ Result BinaryReaderIR::BeginFunctionBody(Index index) { Result BinaryReaderIR::OnLocalDecl(Index decl_index, Index count, Type type) { TypeVector& types = current_func_->local_types; + WABT_TRY types.reserve(types.size() + count); + WABT_CATCH_BAD_ALLOC for (size_t i = 0; i < count; ++i) types.push_back(type); return Result::Ok; @@ -802,7 +818,9 @@ Result BinaryReaderIR::EndFunctionBody(Index index) { } Result BinaryReaderIR::OnElemSegmentCount(Index count) { + WABT_TRY module_->elem_segments.reserve(count); + WABT_CATCH_BAD_ALLOC return Result::Ok; } @@ -830,7 +848,9 @@ Result BinaryReaderIR::OnElemSegmentFunctionIndexCount(Index index, Index count) { assert(index == module_->elem_segments.size() - 1); ElemSegment* segment = module_->elem_segments[index]; + WABT_TRY segment->vars.reserve(count); + WABT_CATCH_BAD_ALLOC return Result::Ok; } @@ -845,7 +865,9 @@ Result BinaryReaderIR::OnElemSegmentFunctionIndex(Index segment_index, } Result BinaryReaderIR::OnDataSegmentCount(Index count) { + WABT_TRY module_->data_segments.reserve(count); + WABT_CATCH_BAD_ALLOC return Result::Ok; } |