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:
Christophe Staïesse
2014-04-01 16:48:26 +02:00
parent 00de7674af
commit 424702b272

View File

@@ -219,9 +219,15 @@ PutMacroArg(char *src, ULONG size)
ULONG
PutUniqueArg(char *src, ULONG size)
{
char *s;
src = src;
yyskipbytes(size);
yyunputstr(sym_FindMacroArg(-1));
if ((s = sym_FindMacroArg(-1)) != NULL) {
yyunputstr(s);
} else {
yyerror("Macro unique label string not defined");
}
return (0);
}