Fixed #960 (Tokenizer::validate() assertion failure with mismatched brackets)

This commit is contained in:
Daniel Marjamäki 2009-11-20 20:10:42 +01:00
parent 7890589693
commit 91f7c15c24
2 changed files with 36 additions and 0 deletions

View File

@ -1508,6 +1508,7 @@ void Tokenizer::simplifyNamespaces()
bool Tokenizer::createLinks()
{
std::list<const Token*> type;
std::list<Token*> links;
std::list<Token*> links2;
std::list<Token*> links3;
@ -1521,6 +1522,7 @@ bool Tokenizer::createLinks()
if (token->str() == "{")
{
links.push_back(token);
type.push_back(token);
}
else if (token->str() == "}")
{
@ -1530,6 +1532,12 @@ bool Tokenizer::createLinks()
syntaxError(token, '{');
return false;
}
if (type.back()->str() != "{")
{
syntaxError(type.back(), type.back()->str()[0]);
return false;
}
type.pop_back();
Token::createMutualLinks(links.back(), token);
links.pop_back();
@ -1537,6 +1545,7 @@ bool Tokenizer::createLinks()
else if (token->str() == "(")
{
links2.push_back(token);
type.push_back(token);
}
else if (token->str() == ")")
{
@ -1546,6 +1555,12 @@ bool Tokenizer::createLinks()
syntaxError(token, '(');
return false;
}
if (type.back()->str() != "(")
{
syntaxError(type.back(), type.back()->str()[0]);
return false;
}
type.pop_back();
Token::createMutualLinks(links2.back(), token);
links2.pop_back();
@ -1553,6 +1568,7 @@ bool Tokenizer::createLinks()
else if (token->str() == "[")
{
links3.push_back(token);
type.push_back(token);
}
else if (token->str() == "]")
{
@ -1562,6 +1578,12 @@ bool Tokenizer::createLinks()
syntaxError(token, '[');
return false;
}
if (type.back()->str() != "[")
{
syntaxError(type.back(), type.back()->str()[0]);
return false;
}
type.pop_back();
Token::createMutualLinks(links3.back(), token);
links3.pop_back();

View File

@ -2439,6 +2439,20 @@ private:
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
ASSERT_EQUALS("[test.cpp:3]: (error) Invalid number of character ([). Can't process file.\n", errout.str());
}
{
errout.str("");
const char code[] = "{\n"
" a(\n"
"}\n"
"{\n"
" b());\n"
"}\n";
Tokenizer tokenizer(0, this);
std::istringstream istr(code);
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
ASSERT_EQUALS("[test.cpp:2]: (error) Invalid number of character ((). Can't process file.\n", errout.str());
}
}
void removeKeywords()