From a6557f8c74688ac5c02f6cb61b303e2039221ad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 2 Apr 2014 19:39:42 +0200 Subject: [PATCH] Null pointer: Fixed false positive discovered by Travis when self-checking cppcheck --- lib/checknullpointer.cpp | 2 +- test/testnullpointer.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 21de12494..5669f506c 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -735,7 +735,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef() nullPointerError(tok2, pointerName, vartok, inconclusive); else if (unknown) nullPointerError(tok2, pointerName, vartok, true); - if (Token::Match(tok2, "%var% ?")) + if (Token::Match(tok2, "%var% %oror%|&&|?")) break; } } diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 229a145ac..3f121dafa 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -1726,6 +1726,12 @@ private: " return q ? p->x : 0;\n" "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str()); + + check("int f(ABC *p) {\n" // FP : return && + " if (!p) {}\n" + " return p && p->x;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } // Test CheckNullPointer::nullConstantDereference @@ -2215,8 +2221,8 @@ private: } void functioncalllibrary() { - Settings settings; - Tokenizer tokenizer(&settings,this); + Settings settings1; + Tokenizer tokenizer(&settings1,this); std::istringstream code("void f() { int a,b; x(a,b); }"); tokenizer.tokenize(code,"test.c"); const Token *xtok = Token::findsimplematch(tokenizer.tokens(), "x");