Memory leaks: simplify 'loop { use ; callfunc ; }' to 'use ;'

This commit is contained in:
Daniel Marjamäki 2010-09-12 20:45:30 +02:00
parent c185f34947
commit 9c4a05a3bd
2 changed files with 11 additions and 0 deletions

View File

@ -1890,6 +1890,16 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false;
}
// loop { use ; callfunc ; } => use ;
// assume that the "callfunc" is not noreturn
if (Token::simpleMatch(tok2, "loop { use ; callfunc ; }"))
{
Token::eraseTokens(tok2, tok2->tokAt(7));
tok2->str("use");
tok2->insertToken(";");
done = false;
}
// Delete if block in "alloc ; if(!var) return ;"
if (Token::Match(tok2, "alloc ; if(!var) return ;"))
{

View File

@ -720,6 +720,7 @@ private:
ASSERT_EQUALS(";", simplifycode("; do { dealloc ; alloc ; } while(var) ;"));
ASSERT_EQUALS("dealloc ; alloc ;", simplifycode("loop { dealloc ; alloc ; }"));
ASSERT_EQUALS("dealloc ; alloc ;", simplifycode("while1 { dealloc ; alloc ; }"));
ASSERT_EQUALS("use ; }", simplifycode("loop { use ; callfunc ; } }"));
// scope..
// current result - ok