-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #11311 Do not search for null pointer in dead code #6442
Conversation
@chrchr-github Unfortunately, I could not find a way to skip tokens of the "false" branch when processing the ternary operator. I can see a function named |
What kind of code do you have in mind? int f(const int* p) {
if (p)
return 0;
return 0 ? *p : 1;
} |
findTokensSkipDeadCode is the function you want to use. It should skip the ternary operator as well. |
Converting this PR to draft. |
There should be no need to reinvent the wheel here. |
27cb64d
to
d2f546c
Compare
You are right, using |
@pfultz2 @chrchr-github I think this PR is now again ready for review. |
lib/checknullpointer.cpp
Outdated
return true; | ||
|
||
while (tok) { | ||
if (isUnevaluated(tok->previous())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you clarify what will tok->previous()
be. if there is parenthesis like ...)tok..
or something then you want to return true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to make sure that the following code does not trigger a warning.
void f(type* p) {
x(sizeof ( (p[0])));
if (!p)
;
}
I need to check whether the variable p
is unevaluated so I used a similar method found in checkuninitvar.cpp
(see method CheckUninitVar::checkExpr
).
lib/checknullpointer.cpp
Outdated
void CheckNullPointer::nullPointerByDeRefAndChec() | ||
static bool isPointerUnevaluated(const Token *tok) | ||
{ | ||
if (isUnevaluated(tok)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be checked in findTokensSkipDeadCodeImpl
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.