Fix #11311 Do not search for null pointer in dead code#6442
Fix #11311 Do not search for null pointer in dead code#6442chrchr-github merged 5 commits intocppcheck-opensource:mainfrom
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. |
| return true; | ||
|
|
||
| while (tok) { | ||
| if (isUnevaluated(tok->previous())) |
There was a problem hiding this comment.
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.
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).
| void CheckNullPointer::nullPointerByDeRefAndChec() | ||
| static bool isPointerUnevaluated(const Token *tok) | ||
| { | ||
| if (isUnevaluated(tok)) |
There was a problem hiding this comment.
This should be checked in findTokensSkipDeadCodeImpl function.
No description provided.