Replace compound_expr_alloc() by {set,list,concat}_expr_alloc() to validate expression type. Signed-off-by: Pablo Neira Ayuso --- include/expression.h | 2 -- src/evaluate.c | 2 +- src/expression.c | 30 ++++++++++++++++-------------- src/parser_bison.y | 8 ++++---- src/parser_json.c | 2 +- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/include/expression.h b/include/expression.h index 198ead603da6..650063bd0e9e 100644 --- a/include/expression.h +++ b/include/expression.h @@ -517,8 +517,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 abbe3bf7e9e5..aa19afd4d0b9 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -5485,7 +5485,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 c0ab5d5598f2..c0d644249a71 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 3022be1ac4e7..fe1d242db98b 100644 --- a/src/parser_bison.y +++ b/src/parser_bison.y @@ -2462,7 +2462,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 @@ -2801,14 +2801,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 @@ -4696,7 +4696,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 17e13ebe4458..cff27a764a9e 100644 --- a/src/parser_json.c +++ b/src/parser_json.c @@ -2990,7 +2990,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; -- 2.30.2