Added check for ## at either end of macro expansion.
This commit is contained in:
@@ -1043,6 +1043,7 @@ static void DoDefine (void)
|
|||||||
Macro* M;
|
Macro* M;
|
||||||
Macro* Existing;
|
Macro* Existing;
|
||||||
int C89;
|
int C89;
|
||||||
|
unsigned Len;
|
||||||
|
|
||||||
/* Read the macro name */
|
/* Read the macro name */
|
||||||
SkipWhitespace (0);
|
SkipWhitespace (0);
|
||||||
@@ -1151,6 +1152,24 @@ static void DoDefine (void)
|
|||||||
printf ("%s: <%.*s>\n", M->Name, SB_GetLen (&M->Replacement), SB_GetConstBuf (&M->Replacement));
|
printf ("%s: <%.*s>\n", M->Name, SB_GetLen (&M->Replacement), SB_GetConstBuf (&M->Replacement));
|
||||||
#endif
|
#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 */
|
/* Get an existing macro definition with this name */
|
||||||
Existing = FindMacro (M->Name);
|
Existing = FindMacro (M->Name);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user