Skip to content

Commit 27cb64d

Browse files
fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! Fix #11311 Do not search for null pointer in dead code
1 parent 1e36c26 commit 27cb64d

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Diff for: lib/checknullpointer.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ const Token * CheckNullPointer::nullPointerByDeRefAndCheck(const Token *start, c
361361
}
362362

363363
/* Analyze condition */
364-
const Token *ifTok = Token::simpleMatch(tok, "if (") ? tok : tok->next()->next()->next();
365-
if (!ifTok || !ifTok->next() || !ifTok->next()->link() || !ifTok->next()->astOperand2()) {
364+
const Token *ifTok = Token::simpleMatch(tok, "if (") ? tok : tok->tokAt(3);
365+
if (!ifTok || !ifTok->next() || !ifTok->linkAt(1) || !ifTok->next()->astOperand2()) {
366366
/* Garbage code */
367367
return end;
368368
}
@@ -412,13 +412,15 @@ const Token * CheckNullPointer::nullPointerByDeRefAndCheck(const Token *start, c
412412
const Token *condTok = tok->astOperand1();
413413
const Token *colonTok = tok->astOperand2();
414414

415-
if (condTok->hasKnownIntValue() && !condTok->getKnownIntValue()) {
416-
/* Skip true branch */
417-
tok = colonTok;
418-
} else {
419-
/* Analyze true branch and skip the other branch */
420-
nullPointerByDeRefAndCheck(tok->next(), colonTok, printInconclusive);
421-
tok = nextAfterAstRightmostLeaf(colonTok);
415+
if (condTok->hasKnownIntValue()) {
416+
if (!condTok->getKnownIntValue()) {
417+
/* Skip true branch */
418+
tok = colonTok;
419+
} else {
420+
/* Analyze true branch and skip the other branch */
421+
nullPointerByDeRefAndCheck(tok->next(), colonTok, printInconclusive);
422+
tok = nextAfterAstRightmostLeaf(colonTok);
423+
}
422424
}
423425
} else {
424426
if (isUnevaluated(tok)) {

0 commit comments

Comments
 (0)