unsigned_lt_zero: re-write this check
commit89bbf415a3c5d73e8d7dfad66d0cc02ca810a6c3
authorDan Carpenter <dan.carpenter@linaro.org>
Wed, 7 Jun 2023 09:40:10 +0000 (7 12:40 +0300)
committerDan Carpenter <dan.carpenter@linaro.org>
Wed, 7 Jun 2023 09:40:10 +0000 (7 12:40 +0300)
tree8f3c27b8bc7592e4526c3f78bb9dcf64f03e9553
parentd78d9a50506ad6f72b0dc2cecc976b161e84d310
unsigned_lt_zero: re-write this check

The warning about unsigned variables less than zero is ancient and bad.
Pull it out into it's own check and re-write it.  The main advantage of
the new check is that it doesn't warn about code like:

if (unsigned_val < 0 || unsigned_val > limit)

The code code is clearly intentional and should not generate a warning.
Smatch already tried to not warn about this but that code was quite
limited.

This code is still not really perfect.  I want to make certain things like
if (x < ARRAY_SIZE()) where array size is zero not print a warning.  Also
I probably want to change the warning message where the variable is not
unsigned but is only treated as unsigned because of type promotion.  But
I'll do that in later patches.

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
check_list.h
check_signed.c
check_unsigned_lt_zero.c [new file with mode: 0644]