diff options
author | Thomas Lively <tlively@google.com> | 2024-08-27 12:50:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-27 12:50:07 -0700 |
commit | 52118e536238c10f6873390a6ca475a44350bc71 (patch) | |
tree | 2023512b05e3d110f5b7d2c452462a0f48c606fc /src/parser/wast-parser.cpp | |
parent | 6c2d0e20906248ab8f8365702b35fd67db29c44f (diff) | |
download | binaryen-52118e536238c10f6873390a6ca475a44350bc71.tar.gz binaryen-52118e536238c10f6873390a6ca475a44350bc71.tar.bz2 binaryen-52118e536238c10f6873390a6ca475a44350bc71.zip |
Check for required actions when parsing wast (#6874)
The parser function for `action` returned a `MaybeResult`, but we were
treating it as returning a normal `Result` and not checking that it had
contents in several places. Replace the current `action()` with
`maybeAction()` and add a new `action()` that requires the action to be
present.
Fixes #6872.
Diffstat (limited to 'src/parser/wast-parser.cpp')
-rw-r--r-- | src/parser/wast-parser.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/parser/wast-parser.cpp b/src/parser/wast-parser.cpp index 5eaf352b7..0f7887f8f 100644 --- a/src/parser/wast-parser.cpp +++ b/src/parser/wast-parser.cpp @@ -49,7 +49,7 @@ Result<Literals> consts(Lexer& in) { return lits; } -MaybeResult<Action> action(Lexer& in) { +MaybeResult<Action> maybeAction(Lexer& in) { if (in.takeSExprStart("invoke"sv)) { auto id = in.takeID(); auto name = in.takeName(); @@ -79,6 +79,14 @@ MaybeResult<Action> action(Lexer& in) { return {}; } +Result<Action> action(Lexer& in) { + if (auto a = maybeAction(in)) { + CHECK_ERR(a); + return *a; + } + return in.err("expected action"); +} + // (module id? binary string*) // (module id? quote string*) // (module ...) @@ -348,7 +356,7 @@ MaybeResult<Assertion> assertTrap(Lexer& in) { return {}; } auto pos = in.getPos(); - if (auto a = action(in)) { + if (auto a = maybeAction(in)) { CHECK_ERR(a); auto msg = in.takeString(); if (!msg) { @@ -423,7 +431,7 @@ Result<WASTCommand> command(Lexer& in) { CHECK_ERR(cmd); return *cmd; } - if (auto cmd = action(in)) { + if (auto cmd = maybeAction(in)) { CHECK_ERR(cmd); return *cmd; } |