From a3367874d9be1d4146d49747b77e1b100d54d9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 9 Oct 2010 07:57:34 +0200 Subject: [PATCH] Fixed #1778 (false negative: nullpointer dereference (std::string pointer)) --- lib/checkother.cpp | 18 ++++++++++-------- test/testother.cpp | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 5523f7bad..d2ff16c91 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2685,14 +2685,16 @@ private: vartok = vartok->tokAt(3); while (vartok && (vartok->str() == "*" || vartok->isName())) vartok = vartok->next(); - if (Token::Match(vartok, "> * %var% ;|=")) - { - vartok = vartok->tokAt(2); - checks.push_back(new CheckNullpointer(owner, vartok->varId(), vartok->str())); - if (Token::simpleMatch(vartok->next(), "= 0 ;")) - setnull(checks, vartok->varId()); - return vartok->next(); - } + } + if (vartok + && (vartok->str() == ">" || vartok->isName()) + && Token::Match(vartok->next(), "* %var% ;|=")) + { + vartok = vartok->tokAt(2); + checks.push_back(new CheckNullpointer(owner, vartok->varId(), vartok->str())); + if (Token::simpleMatch(vartok->next(), "= 0 ;")) + setnull(checks, vartok->varId()); + return vartok->next(); } } diff --git a/test/testother.cpp b/test/testother.cpp index c3f5a4039..29adb8cbc 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1134,7 +1134,7 @@ private: " std::string * x = 0;\n" " *x = \"test\";\n" "}\n"); - TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str()); } void checkUninitVar(const char code[])