From b856925f6c25df22a0901d8f9e24e4247b4acc18 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 8 May 2017 14:05:22 -0700 Subject: text format parsing fixes (#1002) --- src/wasm/wasm-s-parser.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 2290a4972..69509afec 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -48,17 +48,18 @@ Element::List& Element::list() { } Element* Element::operator[](unsigned i) { + if (!isList()) throw ParseException("expected list", line, col); if (i >= list().size()) throw ParseException("expected more elements in list", line, col); return list()[i]; } IString Element::str() { - element_assert(!isList_); + if (!isStr()) throw ParseException("expected string", line, col); return str_; } const char* Element::c_str() { - element_assert(!isList_); + if (!isStr()) throw ParseException("expected string", line, col); return str_.str; } @@ -207,7 +208,8 @@ Element* SExpressionParser::parseString() { } SExpressionWasmBuilder::SExpressionWasmBuilder(Module& wasm, Element& module, Name* moduleName) : wasm(wasm), allocator(wasm.allocator), globalCounter(0) { - assert(module[0]->str() == MODULE); + if (module.size() == 0) throw ParseException("empty toplevel, expected module"); + if (module[0]->str() != MODULE) throw ParseException("toplevel does not start with module"); if (module.size() == 1) return; Index i = 1; if (module[i]->dollared()) { @@ -579,7 +581,6 @@ WasmType SExpressionWasmBuilder::stringToWasmType(const char* str, bool allowErr } Expression* SExpressionWasmBuilder::parseExpression(Element& s) { - assert(s.isList()); IString id = s[0]->str(); const char *str = id.str; const char *dot = strchr(str, '.'); -- cgit v1.2.3