Ticket #6666: Don't crash upon garbage code in CheckLeakAutoVar::checkScope.

This commit is contained in:
Simon Martin 2015-05-10 10:00:46 +02:00
parent 96891dface
commit 27e88fdc47
2 changed files with 9 additions and 1 deletions

View File

@ -150,8 +150,11 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
// Parse all tokens
const Token * const endToken = startToken->link();
for (const Token *tok = startToken; tok && tok != endToken; tok = tok->next()) {
if (!tok->scope()->isExecutable())
if (!tok->scope()->isExecutable()) {
tok = tok->scope()->classEnd;
if (!tok) // Ticket #6666 (crash upon invalid code)
break;
}
// Deallocation and then dereferencing pointer..
if (tok->varId() > 0) {

View File

@ -76,6 +76,7 @@ private:
TEST_CASE(garbageCode35); // #2599, #2604
TEST_CASE(garbageCode36); // #6334
TEST_CASE(garbageCode37); // #5166
TEST_CASE(garbageCode38); // #6666
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
@ -445,6 +446,10 @@ private:
checkCode("void * f { } void b ( ) { * f }");
}
void garbageCode38() { // Ticket #6666
checkCode("{ f2 { } } void f3 () { delete[] } { }");
}
void garbageValueFlow() {
// #6089
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"