From 49ed5b208c0212f3ea92078d040a4ae2bb5efe41 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Tue, 25 Feb 2014 16:34:36 +0300 Subject: [PATCH] states: eliminate remaining references to __get_cur_slist() There was a NULL AVL bug I noticed now that we call avl_count(). Signed-off-by: Dan Carpenter --- avl.c | 2 ++ check_debug.c | 12 ++++++------ smatch.h | 1 - smatch_capped.c | 4 ++-- smatch_db.c | 4 ++-- smatch_function_hooks.c | 2 +- smatch_states.c | 5 ----- 7 files changed, 13 insertions(+), 17 deletions(-) diff --git a/avl.c b/avl.c index 4ada02a7..a0e0b4f2 100644 --- a/avl.c +++ b/avl.c @@ -102,6 +102,8 @@ AvlNode *avl_lookup_node(const AVL *avl, const struct sm_state *sm) size_t avl_count(const AVL *avl) { + if (!avl) + return 0; return avl->count; } diff --git a/check_debug.c b/check_debug.c index 442f890e..2acfdab7 100644 --- a/check_debug.c +++ b/check_debug.c @@ -53,14 +53,14 @@ static void match_state(const char *fn, struct expression *expr, void *info) return; } - FOR_EACH_PTR(__get_cur_slist(), sm) { + FOR_EACH_SM(__get_cur_stree(), sm) { if (strcmp(check_name(sm->owner), check_arg->string->data) != 0) continue; if (strcmp(sm->name, state_arg->string->data) != 0) continue; sm_msg("'%s' = '%s'", sm->name, sm->state->name); found = 1; - } END_FOR_EACH_PTR(sm); + } END_FOR_EACH_SM(sm); if (!found) sm_msg("%s '%s' not found", check_arg->string->data, state_arg->string->data); @@ -78,12 +78,12 @@ static void match_states(const char *fn, struct expression *expr, void *info) return; } - FOR_EACH_PTR(__get_cur_slist(), sm) { + FOR_EACH_SM(__get_cur_stree(), sm) { if (strcmp(check_name(sm->owner), check_arg->string->data) != 0) continue; sm_msg("'%s' = '%s'", sm->name, sm->state->name); found = 1; - } END_FOR_EACH_PTR(sm); + } END_FOR_EACH_SM(sm); if (!found) sm_msg("%s: no states", check_arg->string->data); @@ -443,11 +443,11 @@ static void match_about(const char *fn, struct expression *expr, void *info) return; } - FOR_EACH_PTR(__get_cur_slist(), sm) { + FOR_EACH_SM(__get_cur_stree(), sm) { if (strcmp(sm->name, name) != 0) continue; sm_msg("%s '%s' = '%s'", check_name(sm->owner), sm->name, sm->state->name); - } END_FOR_EACH_PTR(sm); + } END_FOR_EACH_SM(sm); } void check_debug(int id) diff --git a/smatch.h b/smatch.h index 45a17250..1ca9d451 100644 --- a/smatch.h +++ b/smatch.h @@ -463,7 +463,6 @@ void __merge_stree_into_cur(struct AVL *stree); int unreachable(void); void __set_sm(struct sm_state *sm); -struct state_list *__get_cur_slist(void); void __set_true_false_sm(struct sm_state *true_state, struct sm_state *false_state); void nullify_path(void); diff --git a/smatch_capped.c b/smatch_capped.c index be723e01..d03006f6 100644 --- a/smatch_capped.c +++ b/smatch_capped.c @@ -195,7 +195,7 @@ static void print_return_implies_capped(int return_id, char *return_ranges, stru const char *param_name; int param; - FOR_EACH_PTR(__get_cur_slist(), sm) { + FOR_EACH_SM(__get_cur_stree(), sm) { if (sm->owner != my_id) continue; if (sm->state != &capped) @@ -218,7 +218,7 @@ static void print_return_implies_capped(int return_id, char *return_ranges, stru sql_insert_return_states(return_id, return_ranges, CAPPED_DATA, param, param_name, "1"); - } END_FOR_EACH_PTR(sm); + } END_FOR_EACH_SM(sm); } static void db_return_states_capped(struct expression *expr, int param, char *key, char *value) diff --git a/smatch_db.c b/smatch_db.c index 20f72a5e..7a067f58 100644 --- a/smatch_db.c +++ b/smatch_db.c @@ -875,7 +875,7 @@ static int call_return_state_hooks_split_possible(struct expression *expr) /* bail if it gets too complicated */ nr_possible = ptr_list_size((struct ptr_list *)sm->possible); - nr_states = ptr_list_size((struct ptr_list *)__get_cur_slist()); + nr_states = avl_count(__get_cur_stree()); /* * the main thing option_info because we don't want to print a * million lines of output. If someone else, like check_locking.c @@ -971,7 +971,7 @@ static void call_return_state_hooks(struct expression *expr) return_ranges = get_return_ranges_str(expr); return_id++; - nr_states = ptr_list_size((struct ptr_list *)__get_cur_slist()); + nr_states = avl_count(__get_cur_stree()); if (nr_states >= 10000) { match_return_info(return_id, return_ranges, expr); return; diff --git a/smatch_function_hooks.c b/smatch_function_hooks.c index 3adf6871..7fadf4ef 100644 --- a/smatch_function_hooks.c +++ b/smatch_function_hooks.c @@ -615,7 +615,7 @@ static void db_return_states(struct expression *expr) if (expr->fn->type != EXPR_SYMBOL || !expr->fn->symbol) return; - if (!__get_cur_slist()) /* no return functions */ + if (!__get_cur_stree()) /* no return functions */ return; prev_return_id = -1; diff --git a/smatch_states.c b/smatch_states.c index 4cf87474..01c96555 100644 --- a/smatch_states.c +++ b/smatch_states.c @@ -358,11 +358,6 @@ struct AVL *get_all_states_stree(int owner) return get_all_states_from_stree(owner, cur_stree); } -struct state_list *__get_cur_slist(void) -{ - return stree_to_slist(cur_stree); -} - struct AVL *__get_cur_stree(void) { return cur_stree; -- 2.11.4.GIT