Null pointer dereference: sending to output stream

This commit is contained in:
Daniel Marjamäki 2010-01-30 14:40:33 +01:00
parent 8716c771a4
commit 48f3921c36
2 changed files with 8 additions and 1 deletions

View File

@ -1316,7 +1316,7 @@ private:
if (Token::simpleMatch(&tok, "* 0"))
{
if (Token::Match(tok.previous(), "[;{}=+-/(,]") ||
Token::simpleMatch(tok.previous(), "return"))
Token::Match(tok.previous(), "return|<<"))
{
CheckOther *checkOther = dynamic_cast<CheckOther *>(owner);
if (checkOther)

View File

@ -957,6 +957,13 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: abc\n", errout.str());
checkNullPointer("static void foo()\n"
"{\n"
" int *p(0);\n"
" std::cout << *p;"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str());
// no false positive..
checkNullPointer("static void foo()\n"
"{\n"