diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 6329a3938..5b73c007a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1160,7 +1160,11 @@ void CheckOther::nullPointerConditionalAssignment() if (Token::Match(tok2, "%varid%", varid)) { if (Token::Match(tok2, "%varid% . %var% (", varid)) - nullPointerError(tok2, tok->next()->str()); + { + const Token *tempTok = Token::findmatch(_tokenizer->tokens(), "%type% * %varid% [;)=]", varid); + if (tempTok) + nullPointerError(tok2, tok->next()->str()); + } break; } } diff --git a/test/testother.cpp b/test/testother.cpp index 3b195ab82..abe3fc2c4 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -67,6 +67,7 @@ private: TEST_CASE(nullpointer4); TEST_CASE(nullpointer5); // References should not be checked TEST_CASE(nullpointer6); + TEST_CASE(nullpointer7); TEST_CASE(uninitvar1); @@ -921,7 +922,15 @@ private: ASSERT_EQUALS("", errout.str()); } - + void nullpointer7() + { + checkNullPointer("void foo()\n" + "{\n" + " wxLongLong x = 0;\n" + " int y = x.GetValue();\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } void checkUninitVar(const char code[]) {