mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Merge pull request #411 from ISSOtm/recursion_limit
Add a recursion limit
This commit is contained in:
@@ -28,6 +28,8 @@
|
||||
#include "types.h"
|
||||
|
||||
static struct sContext *pFileStack;
|
||||
static unsigned int nFileStackDepth;
|
||||
unsigned int nMaxRecursionDepth;
|
||||
static struct sSymbol *pCurrentMacro;
|
||||
static YY_BUFFER_STATE CurrentFlexHandle;
|
||||
static FILE *pCurrentFile;
|
||||
@@ -51,6 +53,8 @@ uint32_t ulMacroReturnValue;
|
||||
#define STAT_isMacroArg 2
|
||||
#define STAT_isREPTBlock 3
|
||||
|
||||
/* Max context stack size */
|
||||
|
||||
/*
|
||||
* Context push and pop
|
||||
*/
|
||||
@@ -58,6 +62,9 @@ static void pushcontext(void)
|
||||
{
|
||||
struct sContext **ppFileStack;
|
||||
|
||||
if (++nFileStackDepth > nMaxRecursionDepth)
|
||||
fatalerror("Recursion limit (%d) exceeded", nMaxRecursionDepth);
|
||||
|
||||
ppFileStack = &pFileStack;
|
||||
while (*ppFileStack)
|
||||
ppFileStack = &((*ppFileStack)->pNext);
|
||||
@@ -154,6 +161,8 @@ static int32_t popcontext(void)
|
||||
fatalerror("%s: Internal error.", __func__);
|
||||
}
|
||||
|
||||
nFileStackDepth--;
|
||||
|
||||
free(*ppLastFile);
|
||||
*ppLastFile = NULL;
|
||||
yy_switch_to_buffer(CurrentFlexHandle);
|
||||
@@ -413,6 +422,7 @@ void fstk_Init(char *pFileName)
|
||||
if (pCurrentFile == NULL)
|
||||
err(1, "Unable to open file '%s'", pFileName);
|
||||
}
|
||||
nFileStackDepth = 0;
|
||||
|
||||
nMacroCount = 0;
|
||||
nCurrentStatus = STAT_isInclude;
|
||||
|
||||
Reference in New Issue
Block a user