diff --git a/lib/executionpath.cpp b/lib/executionpath.cpp index 96f85e628..c04bf84fd 100644 --- a/lib/executionpath.cpp +++ b/lib/executionpath.cpp @@ -95,6 +95,13 @@ static const Token *checkExecutionPaths_(const Token *tok, std::list bail out + if (Token::simpleMatch(tok, ") {")) + { + ExecutionPath::bailOut(checks); + return 0; + } + if (Token::Match(tok, "abort|exit (")) { ExecutionPath::bailOut(checks); @@ -118,6 +125,19 @@ static const Token *checkExecutionPaths_(const Token *tok, std::listprevious(), "[;{}] {")) + { + const Token *tokerr = checkExecutionPaths_(tok->next(), checks); + if (tokerr) + { + ExecutionPath::bailOut(checks); + return tokerr; + } + tok = tok->link(); + continue; + } + if (tok->str() == "if") { std::list newchecks; diff --git a/test/testother.cpp b/test/testother.cpp index 8f11a8719..4eefbcf61 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1587,6 +1587,34 @@ private: " strchr(s.c_str(), ',');\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // ; { .. } + checkUninitVar("int foo()\n" + "{\n" + " int retval;\n" + " if (condition) {\n" + " { }\n" + " retval = 1; }\n" + " else\n" + " retval = 2;\n" + " return retval;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + // macro_for.. + checkUninitVar("int foo()\n" + "{\n" + " int retval;\n" + " if (condition) {\n" + " for12(1,2) { }\n" + " retval = 1;\n" + " }\n" + " else\n" + " retval = 2;\n" + " return retval;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + }