Fix bug related to ticket #330, cppcheck hanged with some files containing "(("
http://apps.sourceforge.net/trac/cppcheck/ticket/330
This commit is contained in:
parent
a3990648a9
commit
a3be307c03
|
@ -2390,9 +2390,12 @@ bool Tokenizer::simplifyRedundantParanthesis()
|
|||
bool ret = false;
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
while (Token::simpleMatch(tok, "( ("))
|
||||
bool foundSomething = true;
|
||||
while (foundSomething && Token::simpleMatch(tok, "( ("))
|
||||
{
|
||||
foundSomething = false;
|
||||
int parlevel = 0;
|
||||
|
||||
for (Token *tok2 = tok; tok2; tok2 = tok2->next())
|
||||
{
|
||||
if (tok2->str() == "(")
|
||||
|
@ -2408,6 +2411,7 @@ bool Tokenizer::simplifyRedundantParanthesis()
|
|||
tok->deleteNext();
|
||||
tok2->deleteNext();
|
||||
ret = true;
|
||||
foundSomething = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -129,6 +129,7 @@ private:
|
|||
|
||||
TEST_CASE(removeParantheses1); // Ticket #61
|
||||
TEST_CASE(removeParantheses2);
|
||||
TEST_CASE(removeParantheses3);
|
||||
|
||||
TEST_CASE(simplify_numeric_condition);
|
||||
TEST_CASE(tokenize_double);
|
||||
|
@ -1613,8 +1614,25 @@ private:
|
|||
ASSERT_EQUALS(std::string(" void foo ( ) { if ( ! s ) { return ; } }"), ostr.str());
|
||||
}
|
||||
|
||||
void removeParantheses3()
|
||||
{
|
||||
const char code[] = "void foo()\n"
|
||||
"{\n"
|
||||
" if (( true )==true){}\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 ( ( true ) == true ) { } }"), ostr.str());
|
||||
}
|
||||
|
||||
void simplify_numeric_condition()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue