Fixed #2493 (false positive: (error) Possible null pointer dereference: pExpr)

This commit is contained in:
Daniel Marjamäki 2011-01-23 08:38:09 +01:00
parent 9d3b242cd8
commit 86e6822264
2 changed files with 14 additions and 1 deletions

View File

@ -608,7 +608,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
}
}
if (Token::Match(tok2, "goto|return|continue|break|throw|if"))
if (Token::Match(tok2, "goto|return|continue|break|throw|if|switch"))
{
if (Token::Match(tok2, "return * %varid%", varid))
nullPointerError(tok2, tok->strAt(3));

View File

@ -868,6 +868,19 @@ private:
" fred->a();\n"
"}");
ASSERT_EQUALS("", errout.str());
// #2493 - switch
check("void f(Fred *fred) {\n"
" if (fred == NULL) {\n"
" x = 0;\n"
" }\n"
" switch (x) {\n"
" case 1:\n"
" fred->a();\n"
" break;\n"
" };\n"
"}");
ASSERT_EQUALS("", errout.str());
}
// Test CheckNullPointer::nullConstantDereference