Fix ticket #448 (false positive:: resource leak)

http://sourceforge.net/apps/trac/cppcheck/ticket/448
Tokenizer improved to simplify "if( (p)==-1 )"
This commit is contained in:
Reijo Tomperi 2009-07-03 21:57:44 +03:00
parent b2474fd980
commit 26358debcf
2 changed files with 14 additions and 0 deletions

View File

@ -2656,6 +2656,17 @@ bool Tokenizer::simplifyRedundantParanthesis()
ret = true;
}
if (Token::Match(tok->previous(), "( ( %var% )") && tok->next()->varId() != 0)
{
// We have "( var )", remove the paranthesis
tok = tok->previous();
tok->deleteNext();
tok = tok->next();
tok->deleteNext();
ret = true;
continue;
}
if (Token::Match(tok, "( ( %bool% )") ||
Token::Match(tok, "( ( %num% )"))
{

View File

@ -379,6 +379,9 @@ private:
// remove parantheses..
ASSERT_EQUALS("= p ; ", tok("= (p);"));
ASSERT_EQUALS("if ( a < p ) { } ", tok("if(a<(p)){}"));
ASSERT_EQUALS("void f ( ) { int p ; if ( p == -1 ) { } } ", tok("void f(){int p; if((p)==-1){}}"));
ASSERT_EQUALS("void f ( ) { int p ; if ( -1 == p ) { } } ", tok("void f(){int p; if(-1==(p)){}}"));
ASSERT_EQUALS("void f ( ) { int p ; if ( p ) { } } ", tok("void f(){int p; if((p)){}}"));
// keep parantheses..
ASSERT_EQUALS("= a ; ", tok("= (char)a;"));