From d4421fd56d0bb8c867285b0368e25a562636db07 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Tue, 12 Feb 2019 17:52:08 +0300 Subject: [PATCH] db: split zero and non-zero returns Before this would only split NULL vs non-NULL, but now I've made it apply to integers as well. I don't honestly know what I was thinking before to make it only apply to pointers. The "if (ret) {" check is the most common style of error handling in the kernel. Obviously, I would like if I could narrow everything down to negative error codes vs zero but so far I have not been able to do that very well. One thing that I did was that I moved positive from negative before the zero/non-zero check. I'm not totally sure what should have priority and it shouldn't matter much either way... But I've been testing this version so I'm going to commit it. Signed-off-by: Dan Carpenter --- smatch_db.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/smatch_db.c b/smatch_db.c index 738f30fa..bf6d3489 100644 --- a/smatch_db.c +++ b/smatch_db.c @@ -1513,7 +1513,12 @@ static int split_possible_helper(struct sm_state *sm, struct expression *expr) return 0; /* bail if it gets too complicated */ - nr_possible = ptr_list_size((struct ptr_list *)sm->possible); + nr_possible = 0; + FOR_EACH_PTR(sm->possible, tmp) { + if (tmp->merged) + continue; + nr_possible++; + } END_FOR_EACH_PTR(tmp); nr_states = get_db_state_count(); if (nr_states * nr_possible >= 2000) return 0; @@ -1665,7 +1670,7 @@ static int split_positive_from_negative(struct expression *expr) return 1; } -static int call_return_state_hooks_split_null_non_null(struct expression *expr) +static int call_return_state_hooks_split_null_non_null_zero(struct expression *expr) { struct returned_state_callback *cb; struct range_list *rl; @@ -1682,8 +1687,6 @@ static int call_return_state_hooks_split_null_non_null(struct expression *expr) return 0; if (expr->type == EXPR_CALL) return 0; - if (!is_pointer(expr)) - return 0; sm = get_sm_state_expr(SMATCH_EXTRA, expr); if (!sm) @@ -2027,14 +2030,14 @@ static void call_return_state_hooks(struct expression *expr) return; } else if (call_return_state_hooks_split_possible(expr)) { return; - } else if (call_return_state_hooks_split_null_non_null(expr)) { + } else if (split_positive_from_negative(expr)) { + return; + } else if (call_return_state_hooks_split_null_non_null_zero(expr)) { return; } else if (call_return_state_hooks_split_success_fail(expr)) { return; } else if (splitable_function_call(expr)) { return; - } else if (split_positive_from_negative(expr)) { - return; } else if (split_by_bool_param(expr)) { } else if (split_by_null_nonnull_param(expr)) { return; -- 2.11.4.GIT