diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index a8d4a7cb6..24842b3fd 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -484,7 +484,7 @@ void CheckNullPointer::nullPointerStructByDeRefAndChec() // dereference in assignment else if (Token::Match(tok1, "[{};] %var% = %var% . %var%")) { - if (std::string(tok1->strAt(1)) == tok1->strAt(3)) + if (tok1->strAt(1) == tok1->strAt(3)) continue; tok1 = tok1->tokAt(3); } @@ -716,6 +716,12 @@ void CheckNullPointer::nullPointerByDeRefAndChec() if (Token::Match(tok1->tokAt(-2), "%varid% = %varid% .", varid)) { break; + } else if (Token::simpleMatch(tok1->tokAt(-2), "* )") && + Token::Match(tok1->linkAt(-1)->tokAt(-2), "%varid% = (", tok1->varId())) { + break; + } else if (Token::simpleMatch(tok1->tokAt(-3), "* ) (") && + Token::Match(tok1->linkAt(-2)->tokAt(-2), "%varid% = (", tok1->varId())) { + break; } else if (Token::Match(tok1->previous(), "&&|%oror%")) { break; } else if (Token::Match(tok1->tokAt(-2), "&&|%oror% !")) { diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 204d15135..f2f91a05d 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -316,6 +316,12 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("void f(struct ABC *abc) {\n" + " abc = (ABC *)(abc->_next);\n" + " if (abc) { }" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // reassign struct.. check("void foo(struct ABC *abc)\n" "{\n"