From 036b2a84bfd65c9fbf64321b2bb201e3d6a6d056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 1 Feb 2012 20:38:47 +0100 Subject: [PATCH] Fixed #3570 (False Postive for 'nullPointer' check) --- lib/checknullpointer.cpp | 2 +- test/testnullpointer.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 5a7024e63..da50a0e64 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -1221,7 +1221,7 @@ private: /** parse condition. @sa ExecutionPath::parseCondition */ bool parseCondition(const Token &tok, std::list &checks) { for (const Token *tok2 = &tok; tok2; tok2 = tok2->next()) { - if (tok2->str() == "(" || tok2->str() == ")") + if (tok2->str() == "(" || tok2->str() == ")" || tok2->str() == "&&" || tok2->str() == "||") break; bool unknown = owner->inconclusiveFlag(); if (tok2->varId() && (CheckNullPointer::isPointerDeRef(tok2, unknown, symbolDatabase) || unknown)) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index a17e577e4..4cda707f3 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -978,6 +978,31 @@ private: " fred->do_something();\n" "}"); ASSERT_EQUALS("", errout.str()); + + // ticket #3570 - parsing of conditions + { + check("void f() {\n" + " int *p = NULL;\n" + " if (x)\n" + " p = q;\n" + " if (p && *p) { }\n" + "}"); + ASSERT_EQUALS("", errout.str()); + check("void f() {\n" + " int *p = NULL;\n" + " if (x)\n" + " p = q;\n" + " if (!p || *p) { }\n" + "}"); + ASSERT_EQUALS("", errout.str()); + check("void f() {\n" + " int *p = NULL;\n" + " if (x)\n" + " p = q;\n" + " if (p || *p) { }\n" + "}"); + TODO_ASSERT_EQUALS("error", "", errout.str()); + } } // Ticket #2350