From 32688ff4ca6b2d3f5b39eab69c1cfe91b0fca26a Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 25 Jan 2018 17:21:05 +0300 Subject: [PATCH] expr_to_chunk_helper: set *sym when there is only one symbol The truth is I wrote this some time back and have forgotten what the bug was. But presumably it was something like this: You have "foo + 8" and you want to have a symbol pointer. Anyway, I'm sure this is an important bug fix. Signed-off-by: Dan Carpenter --- smatch_helper.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/smatch_helper.c b/smatch_helper.c index dff8ba7c..3aa8f043 100644 --- a/smatch_helper.c +++ b/smatch_helper.c @@ -468,9 +468,7 @@ int get_complication_score(struct expression *expr) score += get_complication_score(expr->right); return score; case EXPR_SYMBOL: - if (is_local_variable(expr)) - return 1; - return 999; + return 1; case EXPR_PREOP: if (expr->op == '*') return score + get_complication_score(expr->unop); @@ -512,6 +510,7 @@ free: char *expr_to_chunk_helper(struct expression *expr, struct symbol **sym, struct var_sym_list **vsl) { + struct var_sym_list *tmp_vsl; char *name; struct symbol *tmp; int score; @@ -539,11 +538,20 @@ char *expr_to_chunk_helper(struct expression *expr, struct symbol **sym, struct if (score <= 0 || score > 2) return NULL; + tmp_vsl = expr_to_vsl(expr); if (vsl) { - *vsl = expr_to_vsl(expr); + *vsl = tmp_vsl; if (!*vsl) return NULL; } + if (sym) { + if (ptr_list_size((struct ptr_list *)tmp_vsl) == 1) { + struct var_sym *vs; + + vs = first_ptr_list((struct ptr_list *)tmp_vsl); + *sym = vs->sym; + } + } expr = reorder_expr_alphabetically(expr); -- 2.11.4.GIT