Fix ticket #600 (Tokenizer: if(!(fclose(fd) == 0)) is simplified incorrectly)
http://sourceforge.net/apps/trac/cppcheck/ticket/600
This commit is contained in:
parent
7d44ce7736
commit
9d1907be66
|
@ -2689,8 +2689,19 @@ bool Tokenizer::simplifyIfNot()
|
||||||
{
|
{
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
|
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()->insertToken("(");
|
||||||
tok->link()->str("!");
|
tok->link()->str("!");
|
||||||
|
}
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -993,6 +993,7 @@ private:
|
||||||
ASSERT_EQUALS("if ( ! x . y )", simplifyIfNot("if(x.y==0)"));
|
ASSERT_EQUALS("if ( ! x . y )", simplifyIfNot("if(x.y==0)"));
|
||||||
ASSERT_EQUALS("if ( ( ! x ) )", simplifyIfNot("if((x==0))"));
|
ASSERT_EQUALS("if ( ( ! x ) )", simplifyIfNot("if((x==0))"));
|
||||||
ASSERT_EQUALS("if ( ( ! x ) && ! y )", simplifyIfNot("if((x==0) && y==0)"));
|
ASSERT_EQUALS("if ( ( ! x ) && ! y )", simplifyIfNot("if((x==0) && y==0)"));
|
||||||
|
ASSERT_EQUALS("if ( ! ( ! fclose ( fd ) ) )", simplifyIfNot("if(!(fclose(fd) == 0))"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue