Fixed #2449 (segfault in tokenize.cpp, incorrect parsing)

This commit is contained in:
Daniel Marjamäki 2011-01-16 11:54:28 +01:00
parent da998fec68
commit f72fd6960e
2 changed files with 28 additions and 0 deletions

View File

@ -2385,6 +2385,27 @@ bool Tokenizer::tokenize(std::istream &code,
// Remove __builtin_expect, likely and unlikely
simplifyBuiltinExpect();
// #2449: syntax error: enum with typedef in it
for (const Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::Match(tok, "enum %var% {"))
{
for (const Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next())
{
if (tok2->str() == "typedef")
{
syntaxError(tok2);
deallocateTokens();
return false;
}
else if (tok2->str() == "}")
{
break;
}
}
}
}
// typedef..
simplifyTypedef();

View File

@ -511,6 +511,13 @@ private:
ASSERT_EQUALS("", tokenizeAndStringify(code.c_str(), true));
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
}
{
errout.str("");
const std::string code("enum ABC { A,B, typedef enum { C } };");
tokenizeAndStringify(code.c_str(), true);
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
}
}
void minus()