Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup!…
Browse files Browse the repository at this point in the history
… Fix #11311 Do not search for null pointer in dead code
  • Loading branch information
francois-berder committed Jun 1, 2024
1 parent 1e36c26 commit 27cb64d
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/checknullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ const Token * CheckNullPointer::nullPointerByDeRefAndCheck(const Token *start, c
}

/* Analyze condition */
const Token *ifTok = Token::simpleMatch(tok, "if (") ? tok : tok->next()->next()->next();
if (!ifTok || !ifTok->next() || !ifTok->next()->link() || !ifTok->next()->astOperand2()) {
const Token *ifTok = Token::simpleMatch(tok, "if (") ? tok : tok->tokAt(3);
if (!ifTok || !ifTok->next() || !ifTok->linkAt(1) || !ifTok->next()->astOperand2()) {
/* Garbage code */
return end;
}
Expand Down Expand Up @@ -412,13 +412,15 @@ const Token * CheckNullPointer::nullPointerByDeRefAndCheck(const Token *start, c
const Token *condTok = tok->astOperand1();
const Token *colonTok = tok->astOperand2();

if (condTok->hasKnownIntValue() && !condTok->getKnownIntValue()) {
/* Skip true branch */
tok = colonTok;
} else {
/* Analyze true branch and skip the other branch */
nullPointerByDeRefAndCheck(tok->next(), colonTok, printInconclusive);
tok = nextAfterAstRightmostLeaf(colonTok);
if (condTok->hasKnownIntValue()) {
if (!condTok->getKnownIntValue()) {
/* Skip true branch */
tok = colonTok;
} else {
/* Analyze true branch and skip the other branch */
nullPointerByDeRefAndCheck(tok->next(), colonTok, printInconclusive);
tok = nextAfterAstRightmostLeaf(colonTok);
}
}
} else {
if (isUnevaluated(tok)) {
Expand Down

0 comments on commit 27cb64d

Please sign in to comment.