Value tracking arrives at incorrect conclusion when incrementing variables in loop conditions
Consider the following program:
#include <stdlib.h>
#include <stdint.h>
#define MAX_VAL (6)
int main()
{
uint32_t val = 0;
do
{
}
while(++val != MAX_VAL);
if(MAX_VAL == val)
{
exit(0);
}
return 0;
}
This program is guaranteed to exit before reaching the return
, however lint claims it is guaranteed to never execute the body of the the if
statement:
info 774: boolean condition for 'if' always evaluates to 'false' (involving variable 'val')
supplemental 831: binary operator yields 0 (line 15)
supplemental 831: increment yields 1 (line 13)
supplemental 831: initialization yields 0 (line 8)
supplemental 831: integral conversion yields 0 (line 8)
supplemental 831: integral conversion yields 6 (line 15)
supplemental 893: expanded from macro 'MAX_VAL' (line 4)
I suspect Lint is confusing val++
for ++val
which would make the warning correct.
1
vote
![](https://secure.gravatar.com/avatar/8bebc6403f26dd66f11c441cf7eb2b36?size=40&default=https%3A%2F%2Fassets.uvcdn.com%2Fpkg%2Fadmin%2Ficons%2Fuser_70-6bcf9e08938533adb9bac95c3e487cb2a6d4a32f890ca6fdc82e3072e0ea0368.png)