Fixed #3415 (Segmentation fault in new check for uninitialized variables)

This commit is contained in:
Daniel Marjamäki 2011-12-15 16:49:14 +01:00
parent 00d6a0e877
commit b3c35d4b32
2 changed files with 12 additions and 0 deletions

View File

@ -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;

View File

@ -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());
}
};