Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! Fix #11311 Do…
Browse files Browse the repository at this point in the history
… not search for null pointer in dead code
  • Loading branch information
francois-berder committed Jun 1, 2024
1 parent e49fc5d commit 13b2cab
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions lib/checknullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ const Token * CheckNullPointer::nullPointerByDeRefAndCheck(const Token *start, c
/* Garbage code */
return end;
}
tok = tok->next()->linkAt(3); /* Skip condition */
tok = tok->linkAt(4); /* Skip condition */
if (!tok || !tok->next() || !tok->next()->link()) {
/* Garbage code */
return end;
Expand All @@ -368,25 +368,21 @@ const Token * CheckNullPointer::nullPointerByDeRefAndCheck(const Token *start, c
}
const Token *condTok = ifTok->next()->astOperand2();
const Token *condStartTok = ifTok->next();
const Token *condEndTok = ifTok->next()->link();
const Token *condEndTok = condStartTok->link();
if (!Token::simpleMatch(condStartTok, "(") || !Token::simpleMatch(condEndTok, ")")) {
/* Garbage code */
return end;
}
tok = nullPointerByDeRefAndCheck(condStartTok, condEndTok, printInconclusive);
if (!tok || !tok->next() || !tok->next()->link()) {
if (!tok || !tok->next() || !tok->linkAt(1)) {
/* Garbage code */
return end;
}

prevBranchTaken = prevBranchTaken || (condTok->hasKnownIntValue() && condTok->getKnownIntValue());
if (condTok->hasKnownIntValue() && condTok->getKnownIntValue() == 0) {
if (!tok->next()->link()) {
/* Garbage code */
return end;
}
/* Skip body */
tok = tok->next()->link();
tok = tok->linkAt(1);
} else {
/* Analyze body */
const Token *elseIfBodyStartTok = tok->next();
Expand All @@ -401,16 +397,16 @@ const Token * CheckNullPointer::nullPointerByDeRefAndCheck(const Token *start, c
/* Garbage code */
return end;
}
} while (Token::simpleMatch(tok->next(), "else { if (") && Token::simpleMatch(tok->next()->linkAt(3), ") {"));
} while (Token::simpleMatch(tok->next(), "else { if (") && Token::simpleMatch(tok->linkAt(4), ") {"));

/* Handle final else branch */
if (prevBranchTaken && Token::simpleMatch(tok->next(), "else")) {
/* Skip body */
if (!tok->next() || !tok->next()->next() || !tok->next()->next()->link()) {
if (!tok->next() || !tok->next()->next() || !tok->linkAt(2)) {
/* Garbage code */
return end;
}
tok = tok->next()->next()->link();
tok = tok->linkAt(2);
}
} else if (Token::simpleMatch(tok, "?") && Token::simpleMatch(tok->astOperand2(), ":")) { // ternary operator
const Token *condTok = tok->astOperand1();
Expand All @@ -421,12 +417,12 @@ const Token * CheckNullPointer::nullPointerByDeRefAndCheck(const Token *start, c
}
} else {
if (isUnevaluated(tok)) {
if (!tok->next() || !tok->next()->link()) {
if (!tok->next() || !tok->linkAt(1)) {
/* Garbage code */
return end;
}

tok = tok->next()->link();
tok = tok->linkAt(1);
} else {
nullPointerByDeRefAndCheckToken(tok, printInconclusive);
}
Expand Down

0 comments on commit 13b2cab

Please sign in to comment.