Memory leaks: simplify 'if break ; break ;'

This commit is contained in:
Daniel Marjamäki 2010-09-11 21:48:40 +02:00
parent 7aa0504692
commit ceeef847ef
2 changed files with 8 additions and 0 deletions

View File

@ -1811,6 +1811,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false;
}
// if break ; break ; => break ;
if (Token::Match(tok2->previous(), "[;{}] if break ; break ;"))
{
Token::eraseTokens(tok2, tok2->tokAt(4));
done = false;
}
// Reduce "do { dealloc ; alloc ; } while(var) ;" => ";"
if (Token::simpleMatch(tok2->next(), "do { dealloc ; alloc ; } while(var) ;"))
{

View File

@ -709,6 +709,7 @@ private:
ASSERT_EQUALS("; alloc ; alloc ;", simplifycode("; alloc ; do { alloc ; } loop ;"));
ASSERT_EQUALS("; exit ;", simplifycode("; alloc ; do { } loop ; exit ;"));
ASSERT_EQUALS("; loop use ;", simplifycode("; loop { loop loop use ; } ;"));
ASSERT_EQUALS("; }", simplifycode("; loop { if break ; break ; } ; }"));
ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; while(!var) alloc ;"));