Fixed #6275: Simplification of = (NULL); to = 0;

This commit is contained in:
PKEuS 2014-11-18 19:38:18 +01:00
parent 85c02df56c
commit 428587f3d4
2 changed files with 2 additions and 1 deletions

View File

@ -1819,7 +1819,7 @@ void Tokenizer::simplifyFileAndLineMacro()
void Tokenizer::simplifyNull()
{
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (tok->str() == "NULL" && !Token::Match(tok->previous(), "[(,] NULL [,)]"))
if (tok->str() == "NULL" && (!Token::Match(tok->previous(), "[(,] NULL [,)]") || tok->strAt(-2) == "="))
tok->str("0");
else if (tok->str() == "__null" || tok->str() == "'\\0'" || tok->str() == "'\\x0'") {
tok->originalName(tok->str());

View File

@ -6197,6 +6197,7 @@ private:
void simplifyNull() {
ASSERT_EQUALS("if ( ! p )", tokenizeAndStringify("if (p==NULL)"));
ASSERT_EQUALS("f ( NULL ) ;", tokenizeAndStringify("f(NULL);"));
ASSERT_EQUALS("char * i ; i = 0 ;", tokenizeAndStringify("char* i = (NULL);"));
}
void simplifyNullArray() {