diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2014-07-15 14:04:00 +0200 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2014-07-22 15:45:02 +0200 |
commit | 5d45e0b69a1ce53d4456a2741acd348a8bb244c3 (patch) | |
tree | 8fd5c4f68dd9a3bb7952bc1828cb01aad1f543d4 /src/libs/3rdparty/cplusplus/Parser.cpp | |
parent | f51553b2287661f115e46ee2f01f085995e1332a (diff) |
C++: block recursion when parsing subsequent case statements.
A case or a default statement must be followed by another statement.
When a such a case (or default) statement is followed immediately by
another case (or default) statement, then this would create a linked
list, and the parser will recurse to parse such input.
In order to prevent the parser running out of stack space while
recursing, parse this corner case by blocking parsing a labeled
statement as the first statement after a labeled statement.
The advantage is that these statements do not form a linked list, so any
subsequent visitation of the AST won't run out of stack space either.
Change-Id: Id2111a49509132997f5fbe4bb12c92c729ec2522
Task-number: QTCREATORBUG-12673
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
Diffstat (limited to 'src/libs/3rdparty/cplusplus/Parser.cpp')
-rw-r--r-- | src/libs/3rdparty/cplusplus/Parser.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/libs/3rdparty/cplusplus/Parser.cpp b/src/libs/3rdparty/cplusplus/Parser.cpp index 333f1e88f8..5023e982dd 100644 --- a/src/libs/3rdparty/cplusplus/Parser.cpp +++ b/src/libs/3rdparty/cplusplus/Parser.cpp @@ -3031,7 +3031,7 @@ bool Parser::parseExpressionStatement(StatementAST *&node) return parsed; } -bool Parser::parseStatement(StatementAST *&node) +bool Parser::parseStatement(StatementAST *&node, bool blockLabeledStatement) { DEBUG_THIS_RULE(); switch (LA()) { @@ -3058,6 +3058,8 @@ bool Parser::parseStatement(StatementAST *&node) case T_CASE: case T_DEFAULT: + if (blockLabeledStatement) + return false; return parseLabeledStatement(node); case T_BREAK: @@ -3126,8 +3128,11 @@ bool Parser::parseStatement(StatementAST *&node) } default: - if (LA() == T_IDENTIFIER && LA(2) == T_COLON) + if (LA() == T_IDENTIFIER && LA(2) == T_COLON) { + if (blockLabeledStatement) + return false; return parseLabeledStatement(node); + } return parseExpressionOrDeclarationStatement(node); } // switch @@ -3598,7 +3603,7 @@ bool Parser::parseLabeledStatement(StatementAST *&node) LabeledStatementAST *ast = new (_pool) LabeledStatementAST; ast->label_token = consumeToken(); ast->colon_token = consumeToken(); - parseStatement(ast->statement); + parseStatement(ast->statement, /*blockLabeledStatement =*/ true); node = ast; return true; } @@ -3608,7 +3613,7 @@ bool Parser::parseLabeledStatement(StatementAST *&node) LabeledStatementAST *ast = new (_pool) LabeledStatementAST; ast->label_token = consumeToken(); match(T_COLON, &ast->colon_token); - parseStatement(ast->statement); + parseStatement(ast->statement, /*blockLabeledStatement =*/ true); node = ast; return true; } @@ -3618,7 +3623,7 @@ bool Parser::parseLabeledStatement(StatementAST *&node) ast->case_token = consumeToken(); parseConstantExpression(ast->expression); match(T_COLON, &ast->colon_token); - parseStatement(ast->statement); + parseStatement(ast->statement, /*blockLabeledStatement =*/ true); node = ast; return true; } |