From eebbc1b906e2983b7065a841d1db9b250639fd76 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Sun, 1 Nov 2009 13:08:37 +0200 Subject: [PATCH] Fix #884 (False positive: Possible null pointer reference about a non-pointer) http://sourceforge.net/apps/trac/cppcheck/ticket/884 --- lib/checkother.cpp | 6 +++++- test/testother.cpp | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) 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[]) {