Fix #771 (False positive. Null pointer dereference in a switch case)
http://sourceforge.net/apps/trac/cppcheck/ticket/771
This commit is contained in:
parent
036f3894f1
commit
6901bcae79
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue