Fix #8192: FN condition always false in for loop condition#8446
Fix #8192: FN condition always false in for loop condition#8446francois-berder wants to merge 1 commit intodanmar:mainfrom
Conversation
When a for loop's condition is impossible given the initial value (e.g. `for (int i = 0; i > 10; i++)`), cppcheck was not emitting a knownConditionTrueFalse warning. Fix by populating memory1, memory2 and memoryAfter with the init state when the condition is immediately false (and no error occured). We can then set the value for the condition token and thus emit a knownConditionTrueFalse warning. Signed-off-by: Francois Berder <[email protected]>
|
|
tweaking the valueflow can have effects in various checkers.. I think it would be interesting if you run cppcheck/tools/test-my-pr.py script on 1000 or so packages and see what the changes are. Will you see more warnings, fewer warnings, which warnings.. A command like |
Unfortunately, I am having trouble testing my PR in this way. While running I also tried in a different way by downloading the DACA2 packages using |



When a for loop's condition is impossible given the initial value (e.g.
for (int i = 0; i > 10; i++)), cppcheck was not emitting a knownConditionTrueFalse warning.Fix by populating memory1, memory2 and memoryAfter with the init state when the condition is immediately false (and no error occured). We can then set the value for the condition token and thus emit a knownConditionTrueFalse warning.