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