Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #3570 (False Postive for 'nullPointer' check)

  • Loading branch information...
commit 036b2a84bfd65c9fbf64321b2bb201e3d6a6d056 1 parent f9ade95
Daniel Marjamäki authored
Showing with 26 additions and 1 deletion.
  1. +1 −1  lib/checknullpointer.cpp
  2. +25 −0 test/testnullpointer.cpp
2  lib/checknullpointer.cpp
View
@@ -1221,7 +1221,7 @@ class Nullpointer : public ExecutionPath {
/** parse condition. @sa ExecutionPath::parseCondition */
bool parseCondition(const Token &tok, std::list<ExecutionPath *> &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))
25 test/testnullpointer.cpp
View
@@ -978,6 +978,31 @@ class TestNullPointer : public TestFixture {
" 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
Please sign in to comment.
Something went wrong with that request. Please try again.