summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2025-08-13 15:21:23 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2025-08-27 23:52:08 +0200
commit65ac6c27886580519e5c7509f82ec1182dd11696 (patch)
tree14b1c92ced67355cf9d1502fea6dd16462b0f287
parent309f5e3c1bf90fff0dd71a4a1af4b1aad0ed6739 (diff)
src: replace compound_expr_alloc() by type safe function
Replace compound_expr_alloc() by {set,list,concat}_expr_alloc() to validate expression type. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--include/expression.h2
-rw-r--r--src/evaluate.c2
-rw-r--r--src/expression.c30
-rw-r--r--src/parser_bison.y8
-rw-r--r--src/parser_json.c2
5 files changed, 22 insertions, 22 deletions
diff --git a/include/expression.h b/include/expression.h
index 32812d28..e73ad90e 100644
--- a/include/expression.h
+++ b/include/expression.h
@@ -523,8 +523,6 @@ extern struct expr *range_expr_alloc(const struct location *loc,
struct expr *low, struct expr *high);
struct expr *range_expr_to_prefix(struct expr *range);
-extern struct expr *compound_expr_alloc(const struct location *loc,
- enum expr_types etypes);
extern void list_expr_sort(struct list_head *head);
extern void list_splice_sorted(struct list_head *list, struct list_head *head);
diff --git a/src/evaluate.c b/src/evaluate.c
index cb05e694..2b1f1c55 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -5497,7 +5497,7 @@ static struct expr *expr_set_to_list(struct eval_ctx *ctx, struct expr *dev_expr
loc = dev_expr->location;
expr_free(dev_expr);
- dev_expr = compound_expr_alloc(&loc, EXPR_LIST);
+ dev_expr = list_expr_alloc(&loc);
list_splice_init(&tmp, &expr_list(dev_expr)->expressions);
return dev_expr;
diff --git a/src/expression.c b/src/expression.c
index 92ab40e2..019c263f 100644
--- a/src/expression.c
+++ b/src/expression.c
@@ -1016,17 +1016,6 @@ struct expr *range_expr_alloc(const struct location *loc,
return expr;
}
-struct expr *compound_expr_alloc(const struct location *loc,
- enum expr_types etype)
-{
- struct expr *expr;
-
- expr = expr_alloc(loc, etype, &invalid_type, BYTEORDER_INVALID, 0);
- /* same layout for EXPR_CONCAT, EXPR_SET and EXPR_LIST. */
- init_list_head(&expr->expr_set.expressions);
- return expr;
-}
-
static void concat_expr_destroy(struct expr *expr)
{
struct expr *i, *next;
@@ -1219,7 +1208,12 @@ static const struct expr_ops concat_expr_ops = {
struct expr *concat_expr_alloc(const struct location *loc)
{
- return compound_expr_alloc(loc, EXPR_CONCAT);
+ struct expr *expr;
+
+ expr = expr_alloc(loc, EXPR_CONCAT, &invalid_type, BYTEORDER_INVALID, 0);
+ init_list_head(&expr_concat(expr)->expressions);
+
+ return expr;
}
void concat_expr_add(struct expr *concat, struct expr *item)
@@ -1276,7 +1270,12 @@ static const struct expr_ops list_expr_ops = {
struct expr *list_expr_alloc(const struct location *loc)
{
- return compound_expr_alloc(loc, EXPR_LIST);
+ struct expr *expr;
+
+ expr = expr_alloc(loc, EXPR_LIST, &invalid_type, BYTEORDER_INVALID, 0);
+ init_list_head(&expr_list(expr)->expressions);
+
+ return expr;
}
void list_expr_add(struct expr *expr, struct expr *item)
@@ -1427,7 +1426,10 @@ static const struct expr_ops set_expr_ops = {
struct expr *set_expr_alloc(const struct location *loc, const struct set *set)
{
- struct expr *set_expr = compound_expr_alloc(loc, EXPR_SET);
+ struct expr *set_expr;
+
+ set_expr = expr_alloc(loc, EXPR_SET, &invalid_type, BYTEORDER_INVALID, 0);
+ init_list_head(&expr_set(set_expr)->expressions);
if (!set)
return set_expr;
diff --git a/src/parser_bison.y b/src/parser_bison.y
index bdcce4c1..3fa75197 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -2502,7 +2502,7 @@ flowtable_expr : '{' flowtable_list_expr '}'
flowtable_list_expr : flowtable_expr_member
{
- $$ = compound_expr_alloc(&@$, EXPR_LIST);
+ $$ = list_expr_alloc(&@$);
list_expr_add($$, $1);
}
| flowtable_list_expr COMMA flowtable_expr_member
@@ -2841,14 +2841,14 @@ dev_spec : DEVICE string
if (!expr)
YYERROR;
- $$ = compound_expr_alloc(&@$, EXPR_LIST);
+ $$ = list_expr_alloc(&@$);
list_expr_add($$, expr);
}
| DEVICE variable_expr
{
datatype_set($2->sym->expr, &ifname_type);
- $$ = compound_expr_alloc(&@$, EXPR_LIST);
+ $$ = list_expr_alloc(&@$);
list_expr_add($$, $2);
}
| DEVICES '=' flowtable_expr
@@ -4748,7 +4748,7 @@ set_rhs_expr : concat_rhs_expr
initializer_expr : rhs_expr
| list_rhs_expr
- | '{' '}' { $$ = compound_expr_alloc(&@$, EXPR_SET); }
+ | '{' '}' { $$ = set_expr_alloc(&@$, NULL); }
| DASH NUM
{
int32_t num = -$2;
diff --git a/src/parser_json.c b/src/parser_json.c
index c107dfc8..e7826250 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -3026,7 +3026,7 @@ static struct expr *ifname_expr_alloc(struct json_ctx *ctx,
static struct expr *json_parse_devs(struct json_ctx *ctx, json_t *root)
{
- struct expr *tmp, *expr = compound_expr_alloc(int_loc, EXPR_LIST);
+ struct expr *tmp, *expr = list_expr_alloc(int_loc);
const char *dev;
json_t *value;
size_t index;