Fix #884 (False positive: Possible null pointer reference about a non-pointer)

http://sourceforge.net/apps/trac/cppcheck/ticket/884
This commit is contained in:
Reijo Tomperi 2009-11-01 13:08:37 +02:00
parent 543d5cbf45
commit eebbc1b906
2 changed files with 15 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -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[])
{