From: Sebastian Harl Date: Sun, 1 Mar 2015 17:36:34 +0000 (+0100) Subject: frontend/grammar: Check arithmetic expressions early. X-Git-Tag: sysdb-0.8.0~146 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=125891926646e7e42dee777a15b79bb9acc2b84a;p=sysdb.git frontend/grammar: Check arithmetic expressions early. Constant expressions are evaluated early. Thus, creating an expression object may fail if there's a semantics error. Catch this early and report a (generic) error to avoid propagating a NULL value. --- diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y index 323fe4f..db3df64 100644 --- a/src/frontend/grammar.y +++ b/src/frontend/grammar.y @@ -166,7 +166,7 @@ sdb_fe_yyerrorf(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *fmt, ...); %type matcher compare_matcher -%type expression object_expression +%type expression arithmetic_expression object_expression %type object_type object_type_plural %type iterable @@ -575,6 +575,31 @@ compare_matcher: ; expression: + arithmetic_expression + { + if (! $1) { + /* we should have better error messages here + * TODO: maybe let the analyzer handle this instead */ + sdb_fe_yyerrorf(&yylloc, scanner, + YY_("syntax error, invalid arithmetic expression")); + YYABORT; + } + $$ = $1; + } + | + object_expression + { + $$ = $1; + } + | + data + { + $$ = sdb_store_expr_constvalue(&$1); + sdb_data_free_datum(&$1); + } + ; + +arithmetic_expression: '(' expression ')' { $$ = $2; @@ -621,17 +646,6 @@ expression: sdb_object_deref(SDB_OBJ($1)); $1 = NULL; sdb_object_deref(SDB_OBJ($3)); $3 = NULL; } - | - object_expression - { - $$ = $1; - } - | - data - { - $$ = sdb_store_expr_constvalue(&$1); - sdb_data_free_datum(&$1); - } ; object_expression: