From 0e14835bbb07a8948b619f43cd18df17d5673271 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 23 Mar 2009 11:39:14 +0300 Subject: [PATCH] change order of condition processing Split the conditions first before passing them to the clients. This means that for: if (!(foo = kmalloc())) { ... the assignment hooks will now be called before the condition hook. Signed-off-by: Dan Carpenter --- check_memory.c | 35 ----------------------------------- check_null_deref.c | 14 ++------------ smatch_conditions.c | 2 +- 3 files changed, 3 insertions(+), 48 deletions(-) diff --git a/check_memory.c b/check_memory.c index 437cea53..ae67f5aa 100644 --- a/check_memory.c +++ b/check_memory.c @@ -139,31 +139,6 @@ static int is_parent(struct expression *expr) return 1; } -static int assign_seen; -static int handle_double_assign(struct expression *expr) -{ - struct symbol *sym; - char *name; - - if (expr->right->type != EXPR_ASSIGNMENT) - return 0; - assign_seen++; - - name = get_variable_from_expr_complex(expr->left, &sym); - if (name && is_parent(expr->left)) - assign_parent(sym); - - name = get_variable_from_expr_complex(expr->right->left, &sym); - if (name && is_parent(expr->right->left)) - assign_parent(sym); - - name = get_variable_from_expr_complex(expr->right->right, &sym); - if (name && is_parent(expr->right->right)) - assign_parent(sym); - - return 1; -} - static void match_assign(struct expression *expr) { struct expression *left, *right; @@ -172,15 +147,6 @@ static void match_assign(struct expression *expr) struct symbol *left_sym, *right_sym; struct smatch_state *state; - if (assign_seen) { - assign_seen--; - return; - } - - if (handle_double_assign(expr)) { - return; - } - left = strip_expr(expr->left); left_name = get_variable_from_expr_complex(left, &left_sym); @@ -318,7 +284,6 @@ static void match_condition(struct expression *expr) free_string(name); return; case EXPR_ASSIGNMENT: - assign_seen++; /* You have to deal with stuff like if (a = b = c) */ match_condition(expr->right); match_condition(expr->left); diff --git a/check_null_deref.c b/check_null_deref.c index 8795eedb..50bb8cee 100644 --- a/check_null_deref.c +++ b/check_null_deref.c @@ -253,17 +253,12 @@ static int check_null_returns(const char *name, struct symbol *sym, return 0; } -static int assign_seen; static void match_assign(struct expression *expr) { struct expression *left, *right; struct symbol *sym; char *name; - if (assign_seen) { - assign_seen--; - return; - } left = strip_expr(expr->left); name = get_variable_from_expr(left, &sym); if (!name) @@ -310,11 +305,7 @@ static void set_new_true_false_paths(const char *name, struct symbol *sym) set_true_false_states(name, my_id, sym, &arg_nonnull, &arg_null); return; } - - if (!tmp || is_maybe_null(name, sym)) { - set_true_false_states(name, my_id, sym, &nonnull, &isnull); - return; - } + set_true_false_states(name, my_id, sym, &nonnull, &isnull); } @@ -335,7 +326,6 @@ static void match_condition(struct expression *expr) free_string(name); return; case EXPR_ASSIGNMENT: - assign_seen++; /* * There is a kernel macro that does * for ( ... ; ... || x = NULL ; ) ... @@ -395,7 +385,7 @@ static void match_dereferences(struct expression *expr) if (is_maybe_null_arg(deref, sym)) { add_do_not_call(sym, get_lineno()); set_state(deref, my_id, sym, &assumed_nonnull); - } else if (is_maybe_null(deref, sym)) { + } else if (is_maybe_null(deref, sym)) { smatch_msg("error: dereferencing undefined: '%s'", deref); set_state(deref, my_id, sym, &ignore); } diff --git a/smatch_conditions.c b/smatch_conditions.c index 76fe7efb..f8d9be12 100644 --- a/smatch_conditions.c +++ b/smatch_conditions.c @@ -261,8 +261,8 @@ static void split_conditions(struct expression *expr) return; } - __pass_to_client(expr, CONDITION_HOOK); __split_expr(expr); + __pass_to_client(expr, CONDITION_HOOK); } static int inside_condition; -- 2.11.4.GIT