memory leaks: better checking of function calls. If there are statements after the function call it is unlikely the function call is noreturn

This commit is contained in:
Daniel Marjamäki 2010-08-02 21:56:50 +02:00
parent c8065506b6
commit df44703ee9
2 changed files with 8 additions and 7 deletions

View File

@ -1462,6 +1462,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
tok2->deleteNext();
}
// reduce "; callfunc ; %var%"
for (Token *tok2 = tok; tok2; tok2 = tok2->next())
{
if (Token::Match(tok2, ";|{|} callfunc ; %type%"))
tok2->deleteNext();
}
// remove redundant braces..
for (Token *start = tok; start; start = start->next())
{
@ -1561,13 +1568,6 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false;
}
// reduce "; callfunc ; %var%"
else if (Token::Match(tok2, "; callfunc ; %type%"))
{
tok2->deleteNext();
done = false;
}
// Reduce "if if|callfunc" => "if"
else if (Token::Match(tok2, "if if|callfunc"))
{

View File

@ -708,6 +708,7 @@ private:
// callfunc..
ASSERT_EQUALS("; callfunc ;", simplifycode(";callfunc;"));
ASSERT_EQUALS("while1 { dealloc ; alloc ; } return ; }", simplifycode("while1 { dealloc ; alloc ; } callfunc ; return ; }"));
// exit..
ASSERT_EQUALS("; exit ;", simplifycode("; alloc; exit;"));