Merge pull request #592 from simartin/ticket_6666

Ticket #6666: Don't crash upon garbage code in CheckLeakAutoVar::checkScope
This commit is contained in:
PKEuS 2015-05-10 22:49:25 +02:00
commit f8d8856d09
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 // Parse all tokens
const Token * const endToken = startToken->link(); const Token * const endToken = startToken->link();
for (const Token *tok = startToken; tok && tok != endToken; tok = tok->next()) { for (const Token *tok = startToken; tok && tok != endToken; tok = tok->next()) {
if (!tok->scope()->isExecutable()) if (!tok->scope()->isExecutable()) {
tok = tok->scope()->classEnd; tok = tok->scope()->classEnd;
if (!tok) // Ticket #6666 (crash upon invalid code)
break;
}
// Deallocation and then dereferencing pointer.. // Deallocation and then dereferencing pointer..
if (tok->varId() > 0) { if (tok->varId() > 0) {

View File

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