mirror of
https://github.com/gbdev/rgbds.git
synced 2026-09-04 12:58:38 +00:00
Disallow minus sign before symbol name in bracketed macro arguments (#2015)
This was being silently allowed but without actually negating the symbol's value
This commit is contained in:
+9
-6
@@ -535,13 +535,16 @@ static uint32_t readBracketedMacroArgNum() {
|
|||||||
int c = peek();
|
int c = peek();
|
||||||
bool empty = false;
|
bool empty = false;
|
||||||
bool symbolError = false;
|
bool symbolError = false;
|
||||||
bool negative = c == '-';
|
|
||||||
|
|
||||||
if (negative) {
|
if (c == '-' || isDigit<10>(c)) {
|
||||||
c = nextChar();
|
bool negative = c == '-';
|
||||||
}
|
if (negative) {
|
||||||
|
c = nextChar();
|
||||||
if (isDigit<10>(c)) {
|
if (!isDigit<10>(c)) {
|
||||||
|
error("No digit after minus sign in bracketed macro argument");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
uint32_t n = readNumber<10>(bumpChar(), nullptr);
|
uint32_t n = readNumber<10>(bumpChar(), nullptr);
|
||||||
if (n > INT32_MAX) {
|
if (n > INT32_MAX) {
|
||||||
error("Number in bracketed macro argument is too large");
|
error("Number in bracketed macro argument is too large");
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
MACRO test
|
||||||
|
println \<2>, " vs ", \<-2>
|
||||||
|
println \<_NARG>, " vs ", \<-_NARG>
|
||||||
|
ENDM
|
||||||
|
test "hello", "goodbye"
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
error: No digit after minus sign in bracketed macro argument
|
||||||
|
at macro-arg-negative-symbol.asm::test(3) <- macro-arg-negative-symbol.asm(5)
|
||||||
|
error: syntax error, unexpected end of line
|
||||||
|
at macro-arg-negative-symbol.asm::test(3) <- macro-arg-negative-symbol.asm(5)
|
||||||
|
Assembly aborted with 2 errors
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
goodbye vs hello
|
||||||
|
goodbye vs
|
||||||
Reference in New Issue
Block a user