Fixed #671 (False positive. Leak when loop is before exit)

This commit is contained in:
Daniel Marjamäki 2009-09-15 22:26:38 +02:00
parent 36c7108a28
commit 5efedf85d6
2 changed files with 14 additions and 5 deletions

View File

@ -1431,16 +1431,24 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
done = false;
}
// Replace "loop ;" with ";"
if (Token::simpleMatch(tok2->next(), "loop ;"))
// Replace "do ; loop ;" with ";"
if (Token::Match(tok2->next(), "%any% ; loop ;"))
{
Token::eraseTokens(tok2, tok2->tokAt(2));
if (tok2->next()->str() == "do")
tok2->deleteNext();
else
tok2 = tok2->next();
Token::eraseTokens(tok2, tok2->tokAt(3));
done = false;
}
// Replace "loop !var ;" with ";"
if (Token::Match(tok2->next(), "loop !var ;"))
// Replace "do ; loop !var ;" with ";"
if (Token::Match(tok2->next(), "%any% ; loop !var ;"))
{
if (tok2->next()->str() == "do")
tok2->deleteNext();
else
tok2 = tok2->next();
Token::eraseTokens(tok2, tok2->tokAt(4));
done = false;
}

View File

@ -469,6 +469,7 @@ private:
ASSERT_EQUALS(";", simplifycode("; loop { if { break; } }"));
ASSERT_EQUALS("; loop alloc ;", simplifycode("; loop { alloc ; }"));
ASSERT_EQUALS("; alloc ; alloc ;", simplifycode("; alloc ; do { alloc ; } loop ;"));
ASSERT_EQUALS("; exit ;", simplifycode("; alloc ; do { } loop ; exit ;"));
// callfunc..
ASSERT_EQUALS("; callfunc ;", simplifycode(";callfunc;", false));