diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 1fbcc6ac9..1fc520f55 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1092,6 +1092,10 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int // goto the } tok = tok->link(); + // TODO: Make sure "if" blocks are surrounded by {} properly (#3415) + if (!tok) + return true; // bail out + if (!Token::Match(tok, "} else {")) { if (initif) { ++number_of_if; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 7d86df3f2..26d6d6513 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1778,6 +1778,14 @@ private: " return x;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // strange code.. don't crash (#3415) + checkUninitVar2("void foo() {\n" + " int i;\n" + " ({ if (0); });\n" + " for_each(i) { }\n" + "}"); + ASSERT_EQUALS("", errout.str()); } };