Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/wast-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3439,7 +3439,11 @@ Result WastParser::ParseModuleCommand(Script* script, CommandPtr* out_command) {
error.loc.offset, error.message.c_str());
}
}
*module = std::move(*m.get());
if (m) {
*module = std::move(*m.get());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for ParseWatModule above to succeed without *m being set?

Would this work instead:

if (errors.length()) { 
  return Result::Error;
}
assert(*m);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't ParseWatModule also return a Result? probably a good idea to check that instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that sounds good. You can do something like this

if (Failed(ParseWatModule(lexer.get(), &m, &errors, options_)) { 
   for (const auto& error : errors) {
      ...
   }
   return Result::Error;
}
assert(errors.length == 0);

} else {
return Result::Error; // Handle the null case appropriately
}
*out_command = std::move(command);
break;
}
Expand Down
8 changes: 8 additions & 0 deletions test/regress/error-quote-module.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
;;; TOOL: wat2wasm
;;; ERROR: 1
(module quote "\7c")
(;; STDERR ;;;
out/test/regress/error-quote-module.txt:3:2: error: error in quoted module: @0x100000001: unexpected token "|", expected a module field or a module.
(module quote "\7c")
^^^^^^
;;; STDERR ;;)
Loading