diff --git a/lib/executionpath.cpp b/lib/executionpath.cpp index 8c6daffc6..99b759572 100644 --- a/lib/executionpath.cpp +++ b/lib/executionpath.cpp @@ -91,11 +91,36 @@ static const Token *checkExecutionPaths_(const Token *tok, std::listnext(); + if (tok2 && tok2->str() == "(") + tok2 = tok2->link(); + if (tok2 && tok2->str() == ")") + tok2 = tok2->next(); + if (!tok2 || tok2->str() != "{") + { + ExecutionPath::bailOut(checks); + return 0; + } + + // skip { .. } + tok2 = tok2->link(); + + // if "do { .. } while ( .." , goto end of while.. + if (Token::simpleMatch(tok, "do {") && Token::simpleMatch(tok2, "} while (")) + tok2 = tok2->tokAt(2)->link(); + + // bail out all variables used in this for/while/switch/do + for (; tok && tok != tok2; tok = tok->next()) + { + if (tok->varId()) + ExecutionPath::bailOutVar(checks, tok->varId()); + } + + continue; } // .. ) { ... } => bail out diff --git a/test/testother.cpp b/test/testother.cpp index d364aa4c8..34a1fa705 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1377,6 +1377,15 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: i\n", errout.str()); + checkUninitVar("void f(int i)\n" + "{\n" + " int a;\n" + " while (i < 10)\n" + " i++;\n" + " a++;" + "}\n"); + ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: a\n", errout.str()); + // member variables.. checkUninitVar("class Fred\n" "{\n"