sval: handle canonical for loops differently
commitd1c72b1a9ddc1d5549660675a6177edbc96f93df
authorDan Carpenter <dan.carpenter@oracle.com>
Mon, 19 Nov 2012 13:20:33 +0000 (19 16:20 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Wed, 21 Nov 2012 12:16:15 +0000 (21 15:16 +0300)
tree7fdefa80282c7f926398551088fe829eaade1eac
parent618b2134f491944663b48d9deefa870e093c5c10
sval: handle canonical for loops differently

The original code doesn't work very well with svals.  I'll first explain
the change and then explain why the original code didn't work.

The old code did a complicated thing where it considered the condition and
tried to get the iterator variable and did some sanity checks.  That isn't
needed because we are given the iterator variable in sm->name and sm->sym.
We also don't care about the condition, we can just look at the max
of the sym->state and add one to know what the value is when we exit the
loop.  It's simpler and the while count down code already works this way.

The reason this code failed is because it looks at the false states which
were never set up correctly. For example in this loop:
for (i = 0; i < (unsigned long)5; i++) { ...
We assume that i can be any value at the start.  The comparison against
(unsigned long)5, means that negative values or positive values greater
than or equal to 5 are false.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch_extra.c