From 90584e898824224ac35c9fea97b7a0978d955741 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 20 Sep 2017 13:30:53 +0300 Subject: [PATCH] estate: estate_is_empty() should return false if the state is NULL An empty is estate is a specific thing that means that the condition is impossible. It's for code like: "foo = NULL; if (foo) { ...". On the other hand if the estate is NULL that means the variable could be anything those are two totally different things. I just added a caller smatch_extra where we check if the estate is empty when handling comparisons with zero and it broke because of this bug. There are two other callers but they were only using it on non-NULL states. Signed-off-by: Dan Carpenter --- smatch_estate.c | 2 +- smatch_math.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/smatch_estate.c b/smatch_estate.c index 1a82db5e..9653429a 100644 --- a/smatch_estate.c +++ b/smatch_estate.c @@ -194,7 +194,7 @@ int estate_is_whole(struct smatch_state *state) int estate_is_empty(struct smatch_state *state) { - return !estate_rl(state); + return state && !estate_rl(state); } int estate_is_unknown(struct smatch_state *state) diff --git a/smatch_math.c b/smatch_math.c index fce42ee2..701d974a 100644 --- a/smatch_math.c +++ b/smatch_math.c @@ -909,7 +909,7 @@ static struct range_list *handle_variable(struct expression *expr, int implied, estate_rl(abs_state))); } else if (estate_rl(state)) { return clone_rl(estate_rl(state)); - } else if (state && estate_is_empty(state)) { + } else if (estate_is_empty(state)) { /* * FIXME: we don't handle empty extra states correctly. * -- 2.11.4.GIT