expression: initialize list of expression to silence gcc compile warning
Pablo Neira Ayuso
maintainerPATCH 1/1 expression: initialize list of expression to silence gcc compile warning
The helper function to translate flagcmp expression to binop expression results in the following compile warning.
src/expression.c: In function 'list_expr_to_binop':
src/expression.c:1286:16: warning: 'last' may be used uninitialized [-Wmaybe-uninitialized]
1286 | return last;
While at it, add assert() to validate the premises where this function can be called.
Fixes 4d5990c92c83 ("src: transform flag match expression to binop expression from parser")
Reported-by Florian Westphal <[email protected]>
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- src/expression.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
src/expression.c +6 -1
@@ -1266,7 +1266,9 @@ struct expr *list_expr_alloc(const struct location *loc)/* list is assumed to have two items at least, otherwise extend this! */ struct expr *list_expr_to_binop (struct expr *expr) { -struct expr *first, *last, *i; +struct expr *first, *last =NULL , *i; + +assert (!list_empty (&expr->expressions)); first = list_first_entry(&expr->expressions, struct expr, list); i = first;
@@ -1279,6 +1281,9 @@ struct expr *list_expr_to_binop(struct expr *expr) last =binop_expr_alloc (&expr->location,OP_OR , i, last); } } +/* list with one single item only, this should not happen. */ +assert (first); +/* zap list expressions, they have been moved to binop expression. */ init_list_head (&expr->expressions);expr_free (expr);
Signature · 1 line
2.30.2