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

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.

1 participant