Fix #713 (Tokenizer: Simplify 0L)

http://sourceforge.net/apps/trac/cppcheck/ticket/713
Use MathLib to handle other variations of 0.
This commit is contained in:
Reijo Tomperi 2009-09-23 22:44:52 +03:00
parent 832481b36e
commit 62ccda5677
2 changed files with 15 additions and 3 deletions

View File

@ -1699,10 +1699,16 @@ void Tokenizer::simplifyTokenList()
// Replace NULL with 0.. // Replace NULL with 0..
for (Token *tok = _tokens; tok; tok = tok->next()) for (Token *tok = _tokens; tok; tok = tok->next())
{ {
if (tok->str() == "NULL" || if (tok->str() == "NULL" || tok->str() == "'\\0'")
tok->str() == "'\\0'" || {
tok->str() == "0L")
tok->str("0"); tok->str("0");
}
else if (tok->isNumber() &&
MathLib::isInt(tok->str()) &&
MathLib::toLongNumber(tok->str()) == 0)
{
tok->str("0");
}
} }
// Replace pointer casts of 0.. "(char *)0" => "0" // Replace pointer casts of 0.. "(char *)0" => "0"

View File

@ -382,6 +382,9 @@ private:
" if (p1 != NULL && p2 == NULL) { ; }\n" " if (p1 != NULL && p2 == NULL) { ; }\n"
" if (p == '\\0');\n" " if (p == '\\0');\n"
" if (p == 0L);\n" " if (p == 0L);\n"
" if (p == 0UL);\n"
" if (p == 0ul);\n"
" if (p == 0l);\n"
"}\n"; "}\n";
ASSERT_EQUALS("void f ( )\n" ASSERT_EQUALS("void f ( )\n"
@ -414,6 +417,9 @@ private:
"if ( p1 && ! p2 ) { ; }\n" "if ( p1 && ! p2 ) { ; }\n"
"if ( ! p ) { ; }\n" "if ( ! p ) { ; }\n"
"if ( ! p ) { ; }\n" "if ( ! p ) { ; }\n"
"if ( ! p ) { ; }\n"
"if ( ! p ) { ; }\n"
"if ( ! p ) { ; }\n"
"}", tokenizeAndStringify(code, true)); "}", tokenizeAndStringify(code, true));
} }