mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Fix bug: rgbasm segfault when \@ is used outside a macro
The problem occurs when \@ is accessed outside the definition of a
macro and is not between "" or {}, or when it is used in an argument of
a macro call, i.e. when the access is processed by PutUniqueArg().
PutUniqueArg(), puts back the string value of \@ to the lexer's buffer
(to substitute \@ by the unique label string).
When \@ is not defined, sym_FindMacroArg(-1) returns NULL, which
yyunputstr() doesn't expect and crashes.
Solution:
Generate an error when \@ is not defined.
Regression test:
SECTION "HOME", HOME
ld a,\@
Will segfault.
On the fixed version, it will return an error as \@ is not available.
This commit is contained in:
@@ -219,9 +219,15 @@ PutMacroArg(char *src, ULONG size)
|
|||||||
ULONG
|
ULONG
|
||||||
PutUniqueArg(char *src, ULONG size)
|
PutUniqueArg(char *src, ULONG size)
|
||||||
{
|
{
|
||||||
|
char *s;
|
||||||
|
|
||||||
src = src;
|
src = src;
|
||||||
yyskipbytes(size);
|
yyskipbytes(size);
|
||||||
yyunputstr(sym_FindMacroArg(-1));
|
if ((s = sym_FindMacroArg(-1)) != NULL) {
|
||||||
|
yyunputstr(s);
|
||||||
|
} else {
|
||||||
|
yyerror("Macro unique label string not defined");
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user