diff --git a/lib/executionpath.cpp b/lib/executionpath.cpp old mode 100755 new mode 100644 index 8603de20f..5196c2015 --- a/lib/executionpath.cpp +++ b/lib/executionpath.cpp @@ -22,6 +22,7 @@ #include #include #include +#include // default : bail out if the condition is has variable handling @@ -62,6 +63,20 @@ bool ExecutionPath::parseCondition(const Token &tok, std::list } +void ExecutionPath::print() const +{ + std::cout << " varId=" << varId + << " numberOfIf=" << numberOfIf + << "\n"; +} + +static void printchecks(const std::list &checks) +{ + for (std::list::const_iterator it = checks.begin(); it != checks.end(); ++it) + (*it)->print(); +} + + static void checkExecutionPaths_(const Token *tok, std::list &checks) { if (!tok || tok->str() == "}" || checks.empty()) @@ -222,16 +237,16 @@ static void checkExecutionPaths_(const Token *tok, std::list &c { std::set countif2; std::list c; - if (checks.size() == 1) - c.push_back(checks.front()->copy()); - else if (!checks.empty()) + if (!checks.empty()) { std::list::const_iterator it; - it = checks.begin(); - while (++it != checks.end()) + for (it = checks.begin(); it != checks.end(); ++it) { - c.push_back((*it)->copy()); - countif2.insert((*it)->varId); + if ((*it)->varId != 0) + { + c.push_back((*it)->copy()); + countif2.insert((*it)->varId); + } } } checkExecutionPaths_(tok->next(), c); diff --git a/lib/executionpath.h b/lib/executionpath.h index 5492afb75..db2f228a8 100644 --- a/lib/executionpath.h +++ b/lib/executionpath.h @@ -50,6 +50,9 @@ public: /** Implement this in each derived class. This function must create a copy of the current instance */ virtual ExecutionPath *copy() = 0; + /** print checkdata */ + void print() const; + /** number of if blocks */ unsigned int numberOfIf; diff --git a/test/testother.cpp b/test/testother.cpp index 970161558..f59d530f8 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1570,6 +1570,19 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("void foo(long verbose,bool bFlag)\n" + "{\n" + " double t;\n" + " if (bFlag)\n" + " {\n" + " if (verbose)\n" + " t = 1;\n" + " if (verbose)\n" + " std::cout << (12-t);\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // switch.. checkUninitVar("char * f()\n" "{\n"