commit ce90dd2cd0d4da45351edbe54a3b9674545ffbd9
parent 720ba6c5d7b45ac586a558f712a0c0bef6b3bbbd
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Wed, 1 Mar 2023 18:16:00 +0100
cc1: Detect wrong cpp concatenation
The concatenation operator cannot happen at the beginning
or at the end of the macro definition but the code was only
testing for the beginning case.
Diffstat:
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/cmd/cc/cc1/cpp.c b/src/cmd/cc/cc1/cpp.c
@@ -501,10 +501,8 @@ getdefs(Symbol *args[NR_MACROARG], int nargs, char *bp, size_t bufsiz)
size_t len;
int prevc = 0, ispar;
- if (yytoken == CONCAT) {
- cpperror("'##' cannot appear at either ends of a macro expansion");
- return 0;
- }
+ if (yytoken == CONCAT)
+ goto wrong_concat;
for (;;) {
ispar = 0;
@@ -545,8 +543,16 @@ getdefs(Symbol *args[NR_MACROARG], int nargs, char *bp, size_t bufsiz)
}
next();
}
+
+ if (prevc == CONCAT)
+ goto wrong_concat;
+
*bp = '\0';
return 1;
+
+wrong_concat:
+ cpperror("'##' cannot appear at either ends of a macro expansion");
+ return 0;
}
static void