forked from qt-creator/qt-creator
Fixed possible crash when parsing template declarations at the end of a C++ file.
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
|
@@ -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;
|
||||||
|
Reference in New Issue
Block a user