From b630de7d895ce24be2cfb6e8cc4e9f651f7156c0 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Tue, 17 Apr 2018 15:18:59 +0300 Subject: [PATCH] expressions: just allocate zero_expr() fresh every time The problem here is that I was thinking about how zero->parent works. We presumably reset it often so the ->parent pointer can point to nonsense. It's probably not a big deal, because of how things are normally parsed but just from a correctness point of view, it seems like the right thing. The other thing is that I changed it to &int_ctype. It shouldn't make any difference but it feels more correct. Probably the most correct thing would be to force people to specify the type... Signed-off-by: Dan Carpenter --- smatch_expressions.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/smatch_expressions.c b/smatch_expressions.c index b5ce6bc9..4c7bde80 100644 --- a/smatch_expressions.c +++ b/smatch_expressions.c @@ -36,14 +36,11 @@ void free_tmp_expressions(void) struct expression *zero_expr(void) { - static struct expression *zero; + struct expression *zero; - if (zero) - return zero; - - zero = alloc_expression(get_cur_pos(), EXPR_VALUE); + zero = alloc_tmp_expression(get_cur_pos(), EXPR_VALUE); zero->value = 0; - zero->ctype = &char_ctype; + zero->ctype = &int_ctype; return zero; } -- 2.11.4.GIT