From 4b6164087e1def828a73ba37a99e7b38d10691d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 15 Apr 2014 06:31:09 +0200 Subject: [PATCH] Use constant instead of magic number for AST recursion limit [ci skip] --- lib/tokenlist.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index c4afd736b..813a1cf7f 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -31,6 +31,12 @@ #include +// How many compileExpression recursions are allowed? +// For practical code this could be endless. But in some special torture test +// there needs to be a limit. +static const unsigned int AST_MAX_DEPTH = 50U; + + TokenList::TokenList(const Settings* settings) : _front(0), _back(0), @@ -702,7 +708,7 @@ static void compileComma(Token *&tok, std::stack &op, unsigned int depth static void compileExpression(Token *&tok, std::stack &op, unsigned int depth) { - if (depth > 300) + if (depth > AST_MAX_DEPTH) return; // ticket #5592 if (tok) compileComma(tok,op, depth+1U);