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 intocppcheck-opensource:mainfrom
Conversation
…ondition 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 <fberder@outlook.fr>
|
|
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 |
I can reproduce that.. will fix it.. |
|
When #8491 has been merged, I suggest you update your main branch and rebase this PR.. and then you should be able to test it out properly. When I tested your changes I got some crashes: I don't know for sure if these crashes was caused by your changes. But I have the feeling that main branch without your changes didn't crash, and my local branch with your changes did crash. |



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.