Fix ticket #600 (Tokenizer: if(!(fclose(fd) == 0)) is simplified incorrectly)

http://sourceforge.net/apps/trac/cppcheck/ticket/600
This commit is contained in:
Reijo Tomperi 2009-08-20 22:37:05 +03:00
parent 7d44ce7736
commit 9d1907be66
2 changed files with 14 additions and 2 deletions

View File

@ -2689,8 +2689,19 @@ bool Tokenizer::simplifyIfNot()
{
tok->deleteNext();
tok->deleteNext();
tok->link()->insertToken("(");
tok->link()->str("!");
if (Token::Match(tok->link()->previous(), "%var%"))
{
// if( foo(x) == 0 )
tok->link()->previous()->insertToken(tok->link()->previous()->str().c_str());
tok->link()->previous()->previous()->str("!");
}
else
{
// if( (x) == 0 )
tok->link()->insertToken("(");
tok->link()->str("!");
}
ret = true;
}
}

View File

@ -993,6 +993,7 @@ private:
ASSERT_EQUALS("if ( ! x . y )", simplifyIfNot("if(x.y==0)"));
ASSERT_EQUALS("if ( ( ! x ) )", simplifyIfNot("if((x==0))"));
ASSERT_EQUALS("if ( ( ! x ) && ! y )", simplifyIfNot("if((x==0) && y==0)"));
ASSERT_EQUALS("if ( ! ( ! fclose ( fd ) ) )", simplifyIfNot("if(!(fclose(fd) == 0))"));
}