Fixed crash on garbage code (#3870)

This commit is contained in:
PKEuS 2012-07-06 09:03:33 -07:00
parent 543ccdd4c0
commit 5caab6ba10
2 changed files with 8 additions and 1 deletions

View File

@ -1162,7 +1162,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
addtoken(&rettail, tok, "loop"); addtoken(&rettail, tok, "loop");
if (varid > 0) { if (varid > 0) {
for (const Token *tok2 = tok->tokAt(2); tok2 != end; tok2 = tok2->next()) { for (const Token *tok2 = tok->tokAt(2); tok2 && tok2 != end; tok2 = tok2->next()) {
if (notvar(tok2, varid)) { if (notvar(tok2, varid)) {
addtoken(&rettail, tok2, "!var"); addtoken(&rettail, tok2, "!var");
break; break;

View File

@ -350,6 +350,8 @@ private:
// #1879 non regression test case // #1879 non regression test case
TEST_CASE(trac1879); TEST_CASE(trac1879);
TEST_CASE(garbageCode);
} }
@ -3805,6 +3807,11 @@ private:
ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: a\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: a\n", errout.str());
} }
void garbageCode() {
check("void h(int l) {\n"
" while\n" // Don't crash (#3870)
"}");
}
}; };