[hackers] [scc] Fix definition of macros with -D || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Mon, 5 Oct 2015 23:09:20 +0200 (CEST)

commit d3cf9edc145d0c14209dd4bb1339778a5c4436fb
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Mon Oct 5 23:08:01 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Mon Oct 5 23:08:01 2015 +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.

diff --git a/cc1/cpp.c b/cc1/cpp.c
index b20ba9a..9063074 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
_AT_@ -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;
Received on Mon Oct 05 2015 - 23:09:20 CEST

This archive was generated by hypermail 2.3.0 : Mon Oct 05 2015 - 23:12:12 CEST