Tokenizer: Fixed bug. When varid is 0 then %varid% doesn't work. Ticket: #2723

This commit is contained in:
Daniel Marjamäki 2011-04-16 17:45:14 +02:00
parent 877a233145
commit 05f59a1567
1 changed files with 4 additions and 3 deletions

View File

@ -6234,9 +6234,10 @@ void Tokenizer::simplifyIfNotNull()
{
if (Token::Match(tok->tokAt(-2), "[;{}] %var%"))
{
const unsigned int varid = tok->previous()->varId();
if (Token::Match(tok, "= ( %varid% != 0 ) ;", varid) ||
Token::Match(tok, "= ( 0 != %varid% ) ;", varid))
const std::string varname(tok->previous()->str());
if (Token::Match(tok->tokAt(2), (varname + " != 0 ) ;").c_str()) ||
Token::Match(tok->tokAt(2), ("0 != " + varname + " ) ;").c_str()))
{
tok = tok->tokAt(-2);
Token::eraseTokens(tok, tok->tokAt(9));