extra: preserve hard_max after comparisons to zero
commit7deff5689fa6618f6c9b72243eca5c4e3c7a4e9d
authorDan Carpenter <dan.carpenter@oracle.com>
Mon, 14 Jan 2019 10:16:17 +0000 (14 13:16 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Mon, 14 Jan 2019 10:16:17 +0000 (14 13:16 +0300)
tree389b85413efdbed7948b5d3489e54f25e7cb9ef4
parenta68847a31053b606bf24739cd981eef0bedeb53a
extra: preserve hard_max after comparisons to zero

John Levon reported that if you had code like:

int lx_cap_mapping[4];
int i = 63;

if (i)
;
lx_cap_mapping[i] = 0;

The code should trigger a warning but it doesn't.

I initially thought the hard_max was getting lost in
merge_estates().  I changed that to say if we were merging an
impossible state with a possible one then we should keep the
hard max from the possible one.  It turns out that wasn't
the issue, but I sort of think it's the correct thing to do
anyway.

The real problem is that we don't preserve the hard_max after
comparisons to zero, whether it's impossible or not.  That is
handled in match_condition().  I changed that function to re-use
handle_comparison().  After that because the original "i" had a
hard_max then handle_comparison() sets the hard_max flag for
both the possible and the impossible sides.

Reported-by: John Levon <levon@movementarian.org>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch_estate.c
smatch_extra.c