mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Truncate long format spec strings before using them (#1299)
Fixes #1293
This commit is contained in:
@@ -724,7 +724,7 @@ static uint32_t readBracketedMacroArgNum(void)
|
||||
}
|
||||
|
||||
if (i == sizeof(symName)) {
|
||||
warning(WARNING_LONG_STR, "Bracketed symbol name too long\n");
|
||||
warning(WARNING_LONG_STR, "Bracketed symbol name too long, got truncated\n");
|
||||
i--;
|
||||
}
|
||||
symName[i] = '\0';
|
||||
@@ -1371,10 +1371,14 @@ static char const *readInterpolation(size_t depth)
|
||||
break;
|
||||
} else if (c == ':' && !fmt_IsFinished(&fmt)) { // Format spec, only once
|
||||
shiftChar();
|
||||
if (i == sizeof(symName)) {
|
||||
warning(WARNING_LONG_STR, "Format spec too long, got truncated\n");
|
||||
i = sizeof(symName) - 1;
|
||||
}
|
||||
symName[i] = '\0';
|
||||
for (size_t j = 0; j < i; j++)
|
||||
fmt_UseCharacter(&fmt, symName[j]);
|
||||
fmt_FinishCharacters(&fmt);
|
||||
symName[i] = '\0';
|
||||
if (!fmt_IsValid(&fmt))
|
||||
error("Invalid format spec '%s'\n", symName);
|
||||
i = 0; // Now that format has been set, restart at beginning of string
|
||||
@@ -1386,7 +1390,7 @@ static char const *readInterpolation(size_t depth)
|
||||
}
|
||||
|
||||
if (i == sizeof(symName)) {
|
||||
warning(WARNING_LONG_STR, "Interpolated symbol name too long\n");
|
||||
warning(WARNING_LONG_STR, "Interpolated symbol name too long, got truncated\n");
|
||||
i--;
|
||||
}
|
||||
symName[i] = '\0';
|
||||
|
||||
@@ -9,7 +9,7 @@ error: bracketed-macro-args.asm(33) -> bracketed-macro-args.asm::bad(29):
|
||||
error: bracketed-macro-args.asm(33) -> bracketed-macro-args.asm::bad(30):
|
||||
Macro argument '\<2>' not defined
|
||||
warning: bracketed-macro-args.asm(39) -> bracketed-macro-args.asm::toolong(36): [-Wlong-string]
|
||||
Bracketed symbol name too long
|
||||
Bracketed symbol name too long, got truncated
|
||||
error: bracketed-macro-args.asm(39) -> bracketed-macro-args.asm::toolong(36):
|
||||
Bracketed symbol "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu" does not exist
|
||||
error: Assembly aborted (6 errors)!
|
||||
|
||||
3
test/asm/long-format-spec.asm
Normal file
3
test/asm/long-format-spec.asm
Normal file
@@ -0,0 +1,3 @@
|
||||
DEF n EQU 42
|
||||
; the format spec is truncated to "000...009", omitting the "x", so this prints "000000042" not "00000002a"
|
||||
PRINTLN "{000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009x:n}"
|
||||
5
test/asm/long-format-spec.err
Normal file
5
test/asm/long-format-spec.err
Normal file
@@ -0,0 +1,5 @@
|
||||
warning: long-format-spec.asm(3): [-Wlong-string]
|
||||
Format spec too long, got truncated
|
||||
error: long-format-spec.asm(3):
|
||||
Invalid format spec '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009'
|
||||
error: Assembly aborted (1 error)!
|
||||
1
test/asm/long-format-spec.out
Normal file
1
test/asm/long-format-spec.out
Normal file
@@ -0,0 +1 @@
|
||||
000000042
|
||||
Reference in New Issue
Block a user