Ticket #6810: Avoid infinite loop upon invalid typed enum declaration.

This commit is contained in:
Simon Martin 2015-07-15 21:35:46 +02:00
parent 38ac8cd594
commit 2d8993319c
2 changed files with 13 additions and 1 deletions

View File

@ -7597,11 +7597,16 @@ void Tokenizer::simplifyEnum()
typeTokenEnd = 0; typeTokenEnd = 0;
while (tok->next() && Token::Match(tok->next(), "::|%type%")) { while (tok->next() && Token::Match(tok->next(), "::|%type%")) {
// Ticket #6810: Avoid infinite loop upon invalid enum definition
if (enumType && enumType->str() == tok->strAt(1)) {
typeTokenEnd = 0;
break;
}
typeTokenEnd = tok->next(); typeTokenEnd = tok->next();
tok = tok->next(); tok = tok->next();
} }
if (!tok->next() || !typeTokenEnd) { if (!tok->next() || tok->str() == "::" || !typeTokenEnd) {
syntaxError(tok); syntaxError(tok);
return; // can't recover return; // can't recover
} }

View File

@ -3188,6 +3188,13 @@ private:
ASSERT_EQUALS(expected, checkSimplifyEnum(code, false)); // Compile as C code: enum has name 'class' ASSERT_EQUALS(expected, checkSimplifyEnum(code, false)); // Compile as C code: enum has name 'class'
checkSimplifyEnum(code, true); // Compile as C++ code: Don't crash checkSimplifyEnum(code, true); // Compile as C++ code: Don't crash
} }
{
// Ticket #6810
ASSERT_THROW(checkSimplifyEnum("enum x : enum x {} :"), InternalError);
ASSERT_THROW(checkSimplifyEnum("enum x : enum x {} () :"), InternalError);
ASSERT_THROW(checkSimplifyEnum("enum x : :: {} () :"), InternalError);
}
} }
void enum16() { // ticket #1988 void enum16() { // ticket #1988