Skip to content

Fix 11887: FP knownPointerToBool with const_cast#5357

Merged
chrchr-github merged 2 commits intocppcheck-opensource:mainfrom
pfultz2:pointer-to-bool-casts
Aug 22, 2023
Merged

Fix 11887: FP knownPointerToBool with const_cast#5357
chrchr-github merged 2 commits intocppcheck-opensource:mainfrom
pfultz2:pointer-to-bool-casts

Conversation

@pfultz2
Copy link
Copy Markdown
Contributor

@pfultz2 pfultz2 commented Aug 21, 2023

No description provided.

Comment thread lib/checkcondition.cpp
if (Token::simpleMatch(tok, "<") && tok->link()) // don't write false positives when templates are used
// don't write false positives when templates are used or inside of asserts or non-evaluated contexts
if (tok->link() && (Token::simpleMatch(tok, "<") ||
Token::Match(tok->previous(), "static_assert|assert|ASSERT|sizeof|decltype ("))) {
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.

We should probably make a helper function for that. We already have isUnevaluatedOperator() and isUnevaluated() (2x) in various places.

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.

And there also is isSizeOfEtc().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well this is checking for unevaluated and for asserts.

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.

Seems like our checks for asserts aren't consistent everywhere either.

@chrchr-github chrchr-github merged commit 2adaafd into cppcheck-opensource:main Aug 22, 2023
@pfultz2 pfultz2 deleted the pointer-to-bool-casts branch September 2, 2023 08:11
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.

3 participants