commit d3cf9edc145d0c14209dd4bb1339778a5c4436fb
parent bcc4c2b84232c42faead193fc05879867f7dc7f2
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Mon, 5 Oct 2015 23:08:01 +0200
Fix definition of macros with -D
A correct macro definition must have the number of
the arguments for this macro, so if we don't add
-1# to the user macro definitions then we can
generate some errors later.
Diffstat:
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/cc1/cpp.c b/cc1/cpp.c
@@ -28,11 +28,17 @@ int disexpand;
Symbol *
defmacro(char *s)
{
- char *p;
+ char *p, *q;
Symbol *sym;
+ size_t len;
- if ((p = strchr(s, '=')) != NULL)
+ if ((p = strchr(s, '=')) != NULL) {
*p++='\0';
+ len = strlen(p);
+ q = xmalloc(len+4);
+ sprintf(q, "-1#%s", p);
+ p = q;
+ }
sym = install(NS_CPP, lookup(NS_CPP, s));
sym->u.s = p;
return sym;