ForwardAnalyzer: Add recursion limit 10000

This commit is contained in:
Daniel Marjamäki 2020-04-09 12:11:33 +02:00
parent 6a3cfdf576
commit e7ddd9cc15
1 changed files with 5 additions and 3 deletions

View File

@ -58,15 +58,17 @@ struct ForwardTraversal {
}
template<class T, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*>)>
Progress traverseRecursive(T* tok, std::function<Progress(T*)> f, bool traverseUnknown) {
Progress traverseRecursive(T* tok, std::function<Progress(T*)> f, bool traverseUnknown, unsigned int recursion=0) {
if (!tok)
return Progress::Continue;
if (tok->astOperand1() && traverseRecursive(tok->astOperand1(), f, traverseUnknown) == Progress::Break)
if (recursion > 10000)
return Progress::Skip;
if (tok->astOperand1() && traverseRecursive(tok->astOperand1(), f, traverseUnknown, recursion+1) == Progress::Break)
return Progress::Break;
Progress p = traverseTok(tok, f, traverseUnknown);
if (p == Progress::Break)
return Progress::Break;
if (p == Progress::Continue && traverseRecursive(tok->astOperand2(), f, traverseUnknown) == Progress::Break)
if (p == Progress::Continue && traverseRecursive(tok->astOperand2(), f, traverseUnknown, recursion+1) == Progress::Break)
return Progress::Break;
return Progress::Continue;
}