Fixed #2226 (segmentation fault of cppcheck)

This commit is contained in:
Daniel Marjamäki 2010-11-24 18:08:21 +01:00
parent c685035ca4
commit fc57e06cdd
2 changed files with 12 additions and 1 deletions

View File

@ -790,13 +790,15 @@ private:
const Token *tok2; const Token *tok2;
// parse setup // parse setup
for (tok2 = tok.tokAt(3); tok2; tok2 = tok2->next()) for (tok2 = tok.tokAt(3); tok2 != tok.link(); tok2 = tok2->next())
{ {
if (tok2->str() == ";") if (tok2->str() == ";")
break; break;
if (tok2->varId()) if (tok2->varId())
varid1.insert(tok2->varId()); varid1.insert(tok2->varId());
} }
if (tok2 == tok.link())
return &tok;
// parse condition // parse condition
if (Token::Match(tok2, "; %var% <|<=|>=|> %num% ;")) if (Token::Match(tok2, "; %var% <|<=|>=|> %num% ;"))

View File

@ -757,6 +757,15 @@ private:
" a++;" " a++;"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: a\n", errout.str()); ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: a\n", errout.str());
// Ticket #2226: C++0x loop
checkUninitVar("void f() {\n"
" container c;\n"
" for (iterator it : c) {\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
// switch.. // switch..