1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-07 23:29:39 +00:00

Added check for ## at either end of macro expansion.

This commit is contained in:
acqn 2022-08-18 23:16:29 +08:00
parent a3a5fbe809
commit cf7558add3

View File

@ -1043,6 +1043,7 @@ static void DoDefine (void)
Macro* M;
Macro* Existing;
int C89;
unsigned Len;
/* Read the macro name */
SkipWhitespace (0);
@ -1151,6 +1152,24 @@ static void DoDefine (void)
printf ("%s: <%.*s>\n", M->Name, SB_GetLen (&M->Replacement), SB_GetConstBuf (&M->Replacement));
#endif
/* Check for ## at start or end */
Len = SB_GetLen (&M->Replacement);
if (Len >= 2) {
if (SB_LookAt (&M->Replacement, 0) == '#' &&
SB_LookAt (&M->Replacement, 1) == '#') {
/* Diagnose and bail out */
PPError ("'##' cannot appear at start of macro expansion");
FreeMacro (M);
return;
} else if (SB_LookAt (&M->Replacement, Len - 1) == '#' &&
SB_LookAt (&M->Replacement, Len - 2) == '#') {
/* Diagnose and bail out */
PPError ("'##' cannot appear at end of macro expansion");
FreeMacro (M);
return;
}
}
/* Get an existing macro definition with this name */
Existing = FindMacro (M->Name);