comparison: handle canonical for loops with variable limit
commitade94255aef13185338c7c2ca80ed6d89cb7fd83
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 26 Mar 2015 15:12:42 +0000 (26 18:12 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Thu, 26 Mar 2015 15:12:42 +0000 (26 18:12 +0300)
treec5c082be58adba225627d24cc7fa3c38e49bc162
parent4c4ece4d3a22a542dc6fe75171c4d299721353d5
comparison: handle canonical for loops with variable limit

This change is not terribly useful on it's own perhaps, but I am partly
doing it to figure out a better way of handling increment, decrement. I'm
hoping that handling this specific case will show how to handle the generic
case.

Here is a canonical for loop:

for (i = 0; i < variable; i++) {

If the limit is a constant then this is handled by SMATCH_EXTRA.
Otherwise, what we want here is to say that at the end of the loop then
"i == variable".  Except, in the fairly common case where we don't know that
"variable" is positive.

What we do is the first time through the loop then we set "i" to the &start
state.  If "i" is incremented once we set it to the &increment state.  If
it's modified other than that, then we set it to undefined.

If, at the end of the loop, i is set to &increment then the false condition
is ==.

This doesn't work for "i <= variable - 1" because that is a stupid way to
write code.  But probably I will update it to handle that later.

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