mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Track nested interpolation depth even outside string literals
Fixes #837
This commit is contained in:
@@ -1280,6 +1280,14 @@ static char const *readInterpolation(unsigned int depth)
|
|||||||
char symName[MAXSYMLEN + 1];
|
char symName[MAXSYMLEN + 1];
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
struct FormatSpec fmt = fmt_NewSpec();
|
struct FormatSpec fmt = fmt_NewSpec();
|
||||||
|
bool disableInterpolation = lexerState->disableInterpolation;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* In a context where `lexerState->disableInterpolation` is true, `peek` will expand
|
||||||
|
* nested interpolations itself, which can lead to stack overflow. This lets
|
||||||
|
* `readInterpolation` handle its own nested expansions, increasing `depth` each time.
|
||||||
|
*/
|
||||||
|
lexerState->disableInterpolation = true;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int c = peek();
|
int c = peek();
|
||||||
@@ -1320,6 +1328,9 @@ static char const *readInterpolation(unsigned int depth)
|
|||||||
}
|
}
|
||||||
symName[i] = '\0';
|
symName[i] = '\0';
|
||||||
|
|
||||||
|
/* Don't return before `lexerState->disableInterpolation` is reset! */
|
||||||
|
lexerState->disableInterpolation = disableInterpolation;
|
||||||
|
|
||||||
static char buf[MAXSTRLEN + 1];
|
static char buf[MAXSTRLEN + 1];
|
||||||
|
|
||||||
struct Symbol const *sym = sym_FindScopedSymbol(symName);
|
struct Symbol const *sym = sym_FindScopedSymbol(symName);
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
def s equs "s"
|
; 128 nested {}s, recursion limit is 64
|
||||||
; 65 nested {}s, recursion limit is 64
|
{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{s}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
|
||||||
println "{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{s}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}"
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
FATAL: nested-interpolation-recursion.asm(3):
|
FATAL: nested-interpolation-recursion.asm(2):
|
||||||
Recursion limit (64) exceeded
|
Recursion limit (64) exceeded
|
||||||
|
|||||||
Reference in New Issue
Block a user