diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 972772a7a202..f04de425415f 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -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; } @@ -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)) {