From 52118e536238c10f6873390a6ca475a44350bc71 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Tue, 27 Aug 2024 12:50:07 -0700 Subject: 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. --- src/parser/wast-parser.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/parser/wast-parser.cpp') 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 consts(Lexer& in) { return lits; } -MaybeResult action(Lexer& in) { +MaybeResult maybeAction(Lexer& in) { if (in.takeSExprStart("invoke"sv)) { auto id = in.takeID(); auto name = in.takeName(); @@ -79,6 +79,14 @@ MaybeResult action(Lexer& in) { return {}; } +Result 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 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 command(Lexer& in) { CHECK_ERR(cmd); return *cmd; } - if (auto cmd = action(in)) { + if (auto cmd = maybeAction(in)) { CHECK_ERR(cmd); return *cmd; } -- cgit v1.2.3