From: Pablo Neira Ayuso Date: Wed, 13 Aug 2025 13:20:43 +0000 (+0200) Subject: expression: replace compound_expr_print() by type safe function X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=309f5e3c1bf90fff0dd71a4a1af4b1aad0ed6739;p=thirdparty%2Fnftables.git expression: replace compound_expr_print() by type safe function Replace compound_expr_print() by {list,set,concat}_expr_print() to validate expression type. Signed-off-by: Pablo Neira Ayuso --- diff --git a/src/expression.c b/src/expression.c index d9456d6b..92ab40e2 100644 --- a/src/expression.c +++ b/src/expression.c @@ -1027,19 +1027,6 @@ struct expr *compound_expr_alloc(const struct location *loc, return expr; } -static void compound_expr_print(const struct expr *expr, const char *delim, - struct output_ctx *octx) -{ - const struct expr *i; - const char *d = ""; - - list_for_each_entry(i, &expr->expr_set.expressions, list) { - nft_print(octx, "%s", d); - expr_print(i, octx); - d = delim; - } -} - static void concat_expr_destroy(struct expr *expr) { struct expr *i, *next; @@ -1050,7 +1037,14 @@ static void concat_expr_destroy(struct expr *expr) static void concat_expr_print(const struct expr *expr, struct output_ctx *octx) { - compound_expr_print(expr, " . ", octx); + const struct expr *i; + const char *d = ""; + + list_for_each_entry(i, &expr_concat(expr)->expressions, list) { + nft_print(octx, "%s", d); + expr_print(i, octx); + d = " . "; + } } static void concat_expr_clone(struct expr *new, const struct expr *expr) @@ -1244,7 +1238,14 @@ void concat_expr_remove(struct expr *concat, struct expr *expr) static void list_expr_print(const struct expr *expr, struct output_ctx *octx) { - compound_expr_print(expr, ",", octx); + const struct expr *i; + const char *d = ""; + + list_for_each_entry(i, &expr_list(expr)->expressions, list) { + nft_print(octx, "%s", d); + expr_print(i, octx); + d = ","; + } } static void list_expr_clone(struct expr *new, const struct expr *expr)