commit f149a192176c7109ebd6f1826a88e324901eff14
parent dd861f58cf7db6cfd625d0540886002ed202b77c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Wed, 26 Oct 2022 21:52:13 +0200
cc1: Detect duplication of parameters in macros
Install() fails when the symbol already exists in the current
context and it return NULL.
Diffstat:
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/cmd/cc/cc1/cpp.c b/src/cmd/cc/cc1/cpp.c
@@ -449,9 +449,12 @@ getpars(Symbol *args[NR_MACROARG])
cpperror("macro arguments must be identifiers");
return NR_MACROARG;
}
- sym = install(NS_IDEN, yylval.sym);
- sym->flags |= SUSED;
- args[n++] = sym;
+ if ((sym = install(NS_IDEN, yylval.sym)) == NULL) {
+ errorp("duplicated macro parameter '%s'", yytext);
+ } else {
+ sym->flags |= SUSED;
+ args[n++] = sym;
+ }
next();
} while (accept(','));
expect(')');