Skip to content

Commit

Permalink
WastParser::ErrorExpected: ensure there is a token to consume (WebAss…
Browse files Browse the repository at this point in the history
…embly#2247)

Fixes assertion failure on empty quoted module
  • Loading branch information
keithw authored Jun 7, 2023
1 parent e828331 commit aca6d6f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/wast-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ void WastParser::ErrorUnlessOpcodeEnabled(const Token& token) {

Result WastParser::ErrorExpected(const std::vector<std::string>& expected,
const char* example) {
GetToken();
Token token = Consume();
std::string expected_str;
if (!expected.empty()) {
Expand Down Expand Up @@ -752,7 +753,6 @@ Result WastParser::ErrorExpected(const std::vector<std::string>& expected,
Result WastParser::ErrorIfLpar(const std::vector<std::string>& expected,
const char* example) {
if (Match(TokenType::Lpar)) {
GetToken();
return ErrorExpected(expected, example);
}
return Result::Ok;
Expand Down
6 changes: 6 additions & 0 deletions test/regress/empty-quoted-module.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;;; TOOL: wat2wasm
;;; ERROR: 1
(module quote "")
(;; STDERR ;;;
out/test/regress/empty-quoted-module.txt:4:1: error: unexpected token "EOF", expected a binary module or a text module.
;;; STDERR ;;)

0 comments on commit aca6d6f

Please sign in to comment.