Fix ticket #344 (Tokenizer crash in Windows)

http://apps.sourceforge.net/trac/cppcheck/ticket/344
This commit is contained in:
Reijo Tomperi 2009-05-31 15:55:06 +03:00
parent aba7518aeb
commit 3fe1b50e60
2 changed files with 19 additions and 9 deletions

View File

@ -2458,15 +2458,6 @@ bool Tokenizer::simplifyRedundantParanthesis()
tok->deleteNext(); tok->deleteNext();
ret = true; ret = true;
} }
if (Token::Match(tok, "( %bool% ) )") ||
Token::Match(tok, "( %num% ) )"))
{
tok = tok->next();
tok->deleteNext();
tok->previous()->deleteThis();
ret = true;
}
} }
return ret; return ret;
} }

View File

@ -1652,6 +1652,25 @@ private:
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void foo ( ) { { } }"), ostr.str()); ASSERT_EQUALS(std::string(" void foo ( ) { { } }"), ostr.str());
} }
{
const char code[] = "void foo()\n"
"{\n"
" if( g(10)){}\n"
"}";
// tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList();
std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void foo ( ) { if ( g ( 10 ) ) { } }"), ostr.str());
}
} }
void simplify_numeric_condition() void simplify_numeric_condition()