Fixed #671 (False positive. Leak when loop is before exit)
This commit is contained in:
parent
36c7108a28
commit
5efedf85d6
|
@ -1431,16 +1431,24 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace "loop ;" with ";"
|
// Replace "do ; loop ;" with ";"
|
||||||
if (Token::simpleMatch(tok2->next(), "loop ;"))
|
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;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace "loop !var ;" with ";"
|
// Replace "do ; loop !var ;" with ";"
|
||||||
if (Token::Match(tok2->next(), "loop !var ;"))
|
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));
|
Token::eraseTokens(tok2, tok2->tokAt(4));
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -469,6 +469,7 @@ private:
|
||||||
ASSERT_EQUALS(";", simplifycode("; loop { if { break; } }"));
|
ASSERT_EQUALS(";", simplifycode("; loop { if { break; } }"));
|
||||||
ASSERT_EQUALS("; loop alloc ;", simplifycode("; loop { alloc ; }"));
|
ASSERT_EQUALS("; loop alloc ;", simplifycode("; loop { alloc ; }"));
|
||||||
ASSERT_EQUALS("; alloc ; alloc ;", simplifycode("; alloc ; do { alloc ; } loop ;"));
|
ASSERT_EQUALS("; alloc ; alloc ;", simplifycode("; alloc ; do { alloc ; } loop ;"));
|
||||||
|
ASSERT_EQUALS("; exit ;", simplifycode("; alloc ; do { } loop ; exit ;"));
|
||||||
|
|
||||||
// callfunc..
|
// callfunc..
|
||||||
ASSERT_EQUALS("; callfunc ;", simplifycode(";callfunc;", false));
|
ASSERT_EQUALS("; callfunc ;", simplifycode(";callfunc;", false));
|
||||||
|
|
Loading…
Reference in New Issue