mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Restore blue-painting of macro arg expansions to prevent recursion
This commit is contained in:
@@ -817,6 +817,11 @@ static int peek() {
|
||||
shiftChar();
|
||||
if (std::shared_ptr<std::string> str = readMacroArg(); str) {
|
||||
beginExpansion(str, std::nullopt);
|
||||
|
||||
// Mark the entire macro arg expansion as "painted blue"
|
||||
// so that macro args can't be recursive
|
||||
// https://en.wikipedia.org/wiki/Painted_blue
|
||||
lexerState->macroArgScanDistance += str->length();
|
||||
}
|
||||
} else if (c == '{' && !lexerState->disableInterpolation) {
|
||||
// If character is an open brace, do symbol interpolation
|
||||
|
||||
6
test/asm/macro-arg-recursion.asm
Normal file
6
test/asm/macro-arg-recursion.asm
Normal file
@@ -0,0 +1,6 @@
|
||||
MACRO m
|
||||
def x = (\1) * 2
|
||||
println "{d:x}"
|
||||
ENDM
|
||||
m 5 ; prints 10
|
||||
m \\2, 6 ; should not prints 12
|
||||
3
test/asm/macro-arg-recursion.err
Normal file
3
test/asm/macro-arg-recursion.err
Normal file
@@ -0,0 +1,3 @@
|
||||
error: macro-arg-recursion.asm(6) -> macro-arg-recursion.asm::m(2):
|
||||
Begun line continuation, but encountered character '2'
|
||||
Assembly aborted with 1 error!
|
||||
2
test/asm/macro-arg-recursion.out
Normal file
2
test/asm/macro-arg-recursion.out
Normal file
@@ -0,0 +1,2 @@
|
||||
10
|
||||
4
|
||||
Reference in New Issue
Block a user