From 34cbcc1bc853fb0a50f92cc2c0ce3a99d2b2b5d5 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 4 Mar 2009 11:27:43 +0300 Subject: [PATCH] Fix bug in compound conditions and add validation test. Signed-off-by: Dan Carpenter --- smatch_slist.c | 5 ++++- validation/sm_compound_condition.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 validation/sm_compound_condition.c diff --git a/smatch_slist.c b/smatch_slist.c index 59591998..8b95da18 100644 --- a/smatch_slist.c +++ b/smatch_slist.c @@ -761,12 +761,15 @@ void or_slist_stack(struct state_list_stack **pre_conds, } END_FOR_EACH_PTR(tmp); free_slist(&tmp_slist2); + tmp_slist2 = clone_slist(cur_slist); + overwrite_slist(new, &tmp_slist2); FOR_EACH_PTR(old, tmp) { - sm = get_sm_state_slist(cur_slist, tmp->name, tmp->owner, + sm = get_sm_state_slist(tmp_slist2, tmp->name, tmp->owner, tmp->sym); new_sm = merge_sm_states(tmp, sm); add_ptr_list(&res, new_sm); } END_FOR_EACH_PTR(tmp); + free_slist(&tmp_slist2); push_slist(slist_stack, res); diff --git a/validation/sm_compound_condition.c b/validation/sm_compound_condition.c new file mode 100644 index 00000000..00301e3d --- /dev/null +++ b/validation/sm_compound_condition.c @@ -0,0 +1,27 @@ +struct ture { + int a; +}; + +struct ture *a; +struct ture *b; + +void func (void) +{ + if (!a && !(a = returns_nonnull())) + return; + a->a = 1; + + if (b || (b = returns_nonnull())) { + b->a = 1; + return; + } + b->a = 1; +} +/* + * check-name: Compound Conditions + * check-command: smatch sm_compound_condition.c + * + * check-output-start +sm_compound_condition.c +18 func(10) Dereferencing Undefined: 'b' + * check-output-end + */ -- 2.11.4.GIT