diff --git a/lib/executionpath.cpp b/lib/executionpath.cpp index 05c1297b4..5ccbcfe2f 100644 --- a/lib/executionpath.cpp +++ b/lib/executionpath.cpp @@ -245,16 +245,20 @@ static void checkExecutionPaths_(const Token *tok, std::list &c std::list::const_iterator it; for (it = checks.begin(); it != checks.end(); ++it) { + c.push_back((*it)->copy()); if ((*it)->varId != 0) - { - c.push_back((*it)->copy()); countif2.insert((*it)->varId); - } } } checkExecutionPaths_(tok->next(), c); while (!c.empty()) { + if (c.back()->varId == 0) + { + c.pop_back(); + continue; + } + bool duplicate = false; std::list::const_iterator it; for (it = checks.begin(); it != checks.end(); ++it) diff --git a/test/testother.cpp b/test/testother.cpp index e861ba823..6abf89ae9 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1411,6 +1411,15 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkNullPointer("void f(int a)\n" + "{\n" + " if (a) {\n" + " char *p;\n" + " *p = 0;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: p\n", errout.str()); + // += checkUninitVar("void f()\n" "{\n"