From 283019a44aee23d2c99c7012451d35ba56b46f28 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 31 May 2010 16:00:59 +0200 Subject: Fixed possible crash when parsing template declarations at the end of a C++ file. --- src/shared/cplusplus/Parser.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/shared/cplusplus/Parser.cpp') diff --git a/src/shared/cplusplus/Parser.cpp b/src/shared/cplusplus/Parser.cpp index 325135838e..6bde85f2e3 100644 --- a/src/shared/cplusplus/Parser.cpp +++ b/src/shared/cplusplus/Parser.cpp @@ -986,7 +986,7 @@ bool Parser::parseTemplateDeclaration(DeclarationAST *&node) match(T_GREATER, &ast->greater_token); } - do { + while (LA()) { unsigned start_declaration = cursor(); ast->declaration = 0; @@ -996,7 +996,7 @@ bool Parser::parseTemplateDeclaration(DeclarationAST *&node) _translationUnit->error(start_declaration, "expected a declaration"); rewind(start_declaration + 1); skipUntilDeclaration(); - } while (LA()); + } node = ast; return true; @@ -5825,3 +5825,11 @@ bool Parser::parseTrailingTypeSpecifierSeq(SpecifierListAST *&node) DEBUG_THIS_RULE(); return parseSimpleTypeSpecifier(node); } + +void Parser::rewind(unsigned cursor) +{ + if (cursor < _translationUnit->tokenCount()) + _tokenIndex = cursor; + else + _tokenIndex = _translationUnit->tokenCount() - 1; +} -- cgit v1.2.1