Fix #771 (False positive. Null pointer dereference in a switch case)

http://sourceforge.net/apps/trac/cppcheck/ticket/771
This commit is contained in:
Reijo Tomperi 2009-10-05 14:46:38 +03:00
parent 036f3894f1
commit 6901bcae79
2 changed files with 16 additions and 1 deletions

View File

@ -866,7 +866,7 @@ void CheckOther::nullPointer()
// Check if the variable is dereferenced..
while (tok2)
{
if (tok2->str() == "{" || tok2->str() == "}")
if (tok2->str() == "{" || tok2->str() == "}" || tok2->str() == "break")
break;
if (tok2->varId() == varid)

View File

@ -628,6 +628,21 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
checkNullPointer("void foo(A*a)\n"
"{\n"
" switch (a->b()) {\n"
" case 1:\n"
" while( a ){\n"
" a = a->next;\n"
" }\n"
" break;\n"
" case 2:\n"
" a->b();\n"
" break;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void nullpointer2()