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 <fw@xxxxxxxxx> Signed-off-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx> --- src/expression.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/expression.c b/src/expression.c index 0b51b22e6103..9f19a379df0f 100644 --- a/src/expression.c +++ b/src/expression.c @@ -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); -- 2.30.2