From a70b0cd0f3ffecbb930ebf6bd2b05b70b84d1e47 Mon Sep 17 00:00:00 2001 From: Lucas Manuel Rodriguez Date: Sat, 24 Aug 2013 16:50:19 -0300 Subject: [PATCH] Fixed FP: Null pointer dereference --- lib/checknullpointer.cpp | 2 +- test/testnullpointer.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index f074e95f2..7a95d9000 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -1204,7 +1204,7 @@ void CheckNullPointer::nullConstantDereference() } const Variable *ovar = 0; - if (Token::Match(tok, "0 ==|!= %var%")) + if (Token::Match(tok, "0 ==|!= %var% !!.")) ovar = tok->tokAt(2)->variable(); else if (Token::Match(tok, "%var% ==|!= 0")) ovar = tok->variable(); diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index abfa309e2..7e65c8411 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -1958,6 +1958,12 @@ private: " std::string s = 0 == x ? \"a\" : \"b\";\n" "}", true); ASSERT_EQUALS("", errout.str()); + + check("void f() {\n" + " const std::string s = g();\n" + " ASSERT_MESSAGE(\"Error on s\", 0 == s.compare(\"Some text\"));\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void nullpointerStdStream() {