Fixed possible crash when parsing template declarations at the end of a C++ file.

This commit is contained in:
Roberto Raggi
2010-05-31 16:00:59 +02:00
parent ecb951cab0
commit 283019a44a
2 changed files with 11 additions and 4 deletions

View File

@@ -986,7 +986,7 @@ bool Parser::parseTemplateDeclaration(DeclarationAST *&node)
match(T_GREATER, &ast->greater_token); match(T_GREATER, &ast->greater_token);
} }
do { while (LA()) {
unsigned start_declaration = cursor(); unsigned start_declaration = cursor();
ast->declaration = 0; ast->declaration = 0;
@@ -996,7 +996,7 @@ bool Parser::parseTemplateDeclaration(DeclarationAST *&node)
_translationUnit->error(start_declaration, "expected a declaration"); _translationUnit->error(start_declaration, "expected a declaration");
rewind(start_declaration + 1); rewind(start_declaration + 1);
skipUntilDeclaration(); skipUntilDeclaration();
} while (LA()); }
node = ast; node = ast;
return true; return true;
@@ -5825,3 +5825,11 @@ bool Parser::parseTrailingTypeSpecifierSeq(SpecifierListAST *&node)
DEBUG_THIS_RULE(); DEBUG_THIS_RULE();
return parseSimpleTypeSpecifier(node); return parseSimpleTypeSpecifier(node);
} }
void Parser::rewind(unsigned cursor)
{
if (cursor < _translationUnit->tokenCount())
_tokenIndex = cursor;
else
_tokenIndex = _translationUnit->tokenCount() - 1;
}

View File

@@ -310,8 +310,7 @@ public:
inline unsigned cursor() const inline unsigned cursor() const
{ return _tokenIndex; } { return _tokenIndex; }
inline void rewind(unsigned cursor) void rewind(unsigned cursor);
{ _tokenIndex = cursor; }
struct TemplateArgumentListEntry { struct TemplateArgumentListEntry {
unsigned index; unsigned index;