Skip to content

Fix #8192: FN condition always false in for loop condition#8446

Open
francois-berder wants to merge 1 commit intodanmar:mainfrom
francois-berder:pr-8192
Open

Fix #8192: FN condition always false in for loop condition#8446
francois-berder wants to merge 1 commit intodanmar:mainfrom
francois-berder:pr-8192

Conversation

@francois-berder
Copy link
Copy Markdown
Contributor

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.

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>
@sonarqubecloud
Copy link
Copy Markdown

@danmar
Copy link
Copy Markdown
Owner

danmar commented Apr 16, 2026

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 python3 tools/test-my-pr.py -p 1000 from inside your branch should work..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants