Fixed #1257 (potential leaks not reported becauseof 'continue' in loop)

This commit is contained in:
Daniel Marjamäki 2010-01-12 19:12:08 +01:00
parent 5e8e4fd3e9
commit 814eb6caee
2 changed files with 12 additions and 3 deletions

View File

@ -1359,10 +1359,17 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
done = false;
}
// Reduce "if return ; if return ;" => "if return ;"
else if (Token::simpleMatch(tok2->next(), "if return ; if return ;"))
// Reduce "if return ; else|if return|continue ;" => "if return ;"
else if (Token::Match(tok2->next(), "if return ; else|if return|continue|break ;"))
{
Token::eraseTokens(tok2, tok2->tokAt(4));
Token::eraseTokens(tok2->tokAt(3), tok2->tokAt(6));
done = false;
}
// Reduce "if continue|break ; else|if return ;" => "if return ;"
else if (Token::Match(tok2->next(), "if continue|break ; if|else return ;"))
{
Token::eraseTokens(tok2->next(), tok2->tokAt(5));
done = false;
}

View File

@ -574,6 +574,8 @@ private:
ASSERT_EQUALS("; alloc ; dealloc ;", simplifycode("; alloc ; if(!var) { alloc ; } dealloc ;"));
ASSERT_EQUALS("; use ;", simplifycode("; if(var) use ;"));
ASSERT_EQUALS("; break ;", simplifycode("; if break ; else break ;"));
ASSERT_EQUALS("; alloc ; if return ;", simplifycode("; alloc ; loop { if return ; if continue ; }"));
ASSERT_EQUALS("; alloc ; if return ;", simplifycode("; alloc ; loop { if continue ; else return ; }"));
ASSERT_EQUALS("; alloc ; dealloc ;\n; alloc ;", simplifycode("; alloc ; if(!var) { return ; } if { dealloc ; }"));
ASSERT_EQUALS("; if alloc ; else assign ; return use ;", simplifycode("; callfunc ; if callfunc { alloc ; } else { assign ; } return use ;"));