From 48f3921c3637e09af1330048a0d394bc84aa6274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 30 Jan 2010 14:40:33 +0100 Subject: [PATCH] Null pointer dereference: sending to output stream --- lib/checkother.cpp | 2 +- test/testother.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 6ad0259a8..0ff5f72f2 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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(owner); if (checkOther) diff --git a/test/testother.cpp b/test/testother.cpp index bfc9b8575..918ae1d81 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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"