From: Pablo Neira Ayuso Date: Mon, 31 Mar 2025 15:15:39 +0000 (+0200) Subject: expression: initialize list of expression to silence gcc compile warning X-Git-Tag: v1.1.2~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=53d6bb9924455644f61d61b18e4d6cf47fc46684;p=thirdparty%2Fnftables.git 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 Signed-off-by: Pablo Neira Ayuso --- diff --git a/src/expression.c b/src/expression.c index d3270242..228754fc 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);