Fixed crash on garbage code (#3870)
This commit is contained in:
parent
543ccdd4c0
commit
5caab6ba10
|
@ -1162,7 +1162,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
|||
addtoken(&rettail, tok, "loop");
|
||||
|
||||
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)) {
|
||||
addtoken(&rettail, tok2, "!var");
|
||||
break;
|
||||
|
|
|
@ -350,6 +350,8 @@ private:
|
|||
|
||||
// #1879 non regression test case
|
||||
TEST_CASE(trac1879);
|
||||
|
||||
TEST_CASE(garbageCode);
|
||||
}
|
||||
|
||||
|
||||
|
@ -3805,6 +3807,11 @@ private:
|
|||
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)
|
||||
"}");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue