Skip to content

Fix #8545 FN Condition '...' is always true ' uint16_t i; ( i <= 0xFFFF)'#4114

Merged
danmar merged 6 commits intocppcheck-opensource:mainfrom
chrchr-github:chr_Fix8545
May 21, 2022
Merged

Fix #8545 FN Condition '...' is always true ' uint16_t i; ( i <= 0xFFFF)'#4114
danmar merged 6 commits intocppcheck-opensource:mainfrom
chrchr-github:chr_Fix8545

Conversation

@chrchr-github
Copy link
Copy Markdown
Collaborator

No description provided.

@chrchr-github
Copy link
Copy Markdown
Collaborator Author

Without the suppression, CMake test fails.
With the added suppression, runtests.sh complains about an unmatched suppression.
Are these checks using different platforms or something?

Comment thread test/cfg/googletest.cpp

unsigned int u = errno;
// cppcheck-suppress unsignedPositive
// cppcheck-suppress [unsignedPositive, compareValueOutOfTypeRangeError]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting - I thought the format was cppcheck-suppress id1;id2.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the manual: // cppcheck-suppress [aaaa, bbbb]

@firewave
Copy link
Copy Markdown
Collaborator

Without the suppression, CMake test fails.
With the added suppression, runtests.sh complains about an unmatched suppression.

In the same job or different ones? Maybe a FILESDIR issue?

Are these checks using different platforms or something?

The only case I am aware of is with a Windows binary - see https://trac.cppcheck.net/ticket/10850#comment:2.

@pfultz2
Copy link
Copy Markdown
Contributor

pfultz2 commented May 18, 2022

I feel like this would be better in fixed in ValueFlow as this could enable inferring more values and improving non-style checks. In valueFlowImpossibleValues, we set out of range values to impossible, for example booleans are set to !<=-1 and !>=-2 here:

https://github.com/danmar/cppcheck/blob/main/lib/valueflow.cpp#L1650

We could add the impossible values for integers smaller than 32 bits, but several unit tests for valueflow may need to be updated to use removeImpossible.

@chrchr-github
Copy link
Copy Markdown
Collaborator Author

There also is some overlap with unsignedLessThanZero and unsignedPositive.

@danmar danmar merged commit 2a7f00c into cppcheck-opensource:main May 21, 2022
@chrchr-github chrchr-github deleted the chr_Fix8545 branch June 22, 2022 14:14
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.

4 participants