diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-05-20 16:00:40 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-05-20 16:04:19 +0200 |
commit | 081871e18db544e2c834a516950e1c16c9bc4d2c (patch) | |
tree | a518d9229859f527253794eb0f4f6339e1dc6ea9 /compiler.c | |
parent | 090b426b00a82cac7b4ea386b077e21ae32f1c17 (diff) |
compiler: fix segmentation fault on compiling unexpected unary expressions
When compiling expressions followed by a unary operator, the compiler
triggered a segmentation fault due to invoking an unset infix parser
routine.
Explicitly handle this case and raise a syntax error if such an
invalid expression is encountered.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'compiler.c')
-rw-r--r-- | compiler.c | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -372,6 +372,13 @@ uc_compiler_parse_precedence(uc_compiler_t *compiler, uc_precedence_t precedence rule = uc_compiler_parse_rule(compiler->exprstack->token); + if (!rule->infix) { + uc_compiler_syntax_error(compiler, compiler->parser->curr.pos, "Expecting ';' or binary operator"); + uc_compiler_parse_advance(compiler); + + return; + } + /* allow reserved words in property accessors */ if (rule->infix == uc_compiler_compile_dot) compiler->parser->lex.no_keyword = true; |