comparison: improve handling of "if (foo + 1 > limit) "
commit6824942e41f19b63440627848b32536f995ea162
authorDan Carpenter <dan.carpenter@oracle.com>
Mon, 19 Feb 2018 13:52:29 +0000 (19 16:52 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Mon, 19 Feb 2018 13:52:29 +0000 (19 16:52 +0300)
tree81cd37ec2b40ca0d10e4b9c960fd1853cd73a219
parent39ac477896370d324f1f73bdf498f7fc6e5d3ac1
comparison: improve handling of "if (foo + 1 > limit) "

We could have a condition "if (foo < limit - 1) " or
"if (foo + 1 < limit)".  It's basically the same.  But then it's hard to
compare because we could compare "offset < limit - 1" but do
"array[offset + 1]".  So it becomes an issue that the comparison and use
don't match exactly.

Let's work around that by always writing the comparison as a minus.  So
we move the "+ 1" to the other side of the equation to become "- 1" with
algebra.

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