Allow changing recursion depth limit at runtime

This commit is contained in:
ISSOtm
2022-02-05 12:15:32 +01:00
committed by Eldred Habert
parent 6842c831fd
commit 7dd8ba37f1
9 changed files with 80 additions and 12 deletions

View File

@@ -668,14 +668,8 @@ static void beginExpansion(char const *str, bool owned, char const *name)
if (!size)
return;
if (name) {
size_t depth = 0;
for (struct Expansion *exp = lexerState->expansions; exp; exp = exp->parent) {
if (depth++ >= maxRecursionDepth)
fatalerror("Recursion limit (%zu) exceeded\n", maxRecursionDepth);
}
}
if (name)
lexer_CheckRecursionDepth();
struct Expansion *exp = malloc(sizeof(*exp));
@@ -692,6 +686,16 @@ static void beginExpansion(char const *str, bool owned, char const *name)
lexerState->expansions = exp;
}
void lexer_CheckRecursionDepth(void)
{
size_t depth = 0;
for (struct Expansion *exp = lexerState->expansions; exp; exp = exp->parent) {
if (depth++ >= maxRecursionDepth)
fatalerror("Recursion limit (%zu) exceeded\n", maxRecursionDepth);
}
}
static void freeExpansion(struct Expansion *expansion)
{
free(expansion->name);