[hackers] [scc] [cc1] Don't allocate INPUTSIZ buffers in macro expansion || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 11 Jan 2017 16:53:20 +0100 (CET)

commit 9d9760579d87a8a5b22de85cd966ac57bfbc7e4d
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed Jan 11 16:19:29 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Jan 11 16:19:29 2017 +0100

    [cc1] Don't allocate INPUTSIZ buffers in macro expansion
    
    Calling addinput() in macro expansion had the effect that
    all the buffers had the size INPUTSIZ, even when it is
    not required. This patch passes a new parameter to addinput()
    which is directly passed to allocinput().

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 7485a34..c8095d6 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -394,7 +394,7 @@ extern unsigned next(void);
 extern int moreinput(void);
 extern void expect(unsigned tok);
 extern void discard(void);
-extern int addinput(char *fname, Symbol *hide);
+extern int addinput(char *fname, Symbol *hide, char *buffer);
 extern void allocinput(char *fname, FILE *fp, char *line);
 extern void delinput(void);
 extern void setsafe(int type);
diff --git a/cc1/cpp.c b/cc1/cpp.c
index 2d77b16..79d57b2 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
_AT_@ -267,10 +267,9 @@ expand(char *begin, Symbol *sym)
 
 substitute:
         DBG("MACRO '%s' expanded to :'%s'", macroname, buffer);
+ buffer[elen] = '\0';
+ addinput(NULL, sym, xstrdup(buffer));
 
- addinput(NULL, sym);
- memcpy(input->line, buffer, elen);
- input->line[elen] = '\0';
         return 1;
 }
 
_AT_@ -430,7 +429,7 @@ includefile(char *dir, char *file, size_t filelen)
         memcpy(path+dirlen, file, filelen);
         path[dirlen + filelen] = '\0';
 
- return addinput(path, NULL);
+ return addinput(path, NULL, NULL);
 }
 
 static void
diff --git a/cc1/lex.c b/cc1/lex.c
index f190154..fd55f1b 100644
--- a/cc1/lex.c
+++ b/cc1/lex.c
_AT_@ -86,7 +86,7 @@ ilex(void)
 }
 
 int
-addinput(char *fname, Symbol *hide)
+addinput(char *fname, Symbol *hide, char *buffer)
 {
         FILE *fp;
         unsigned nline = 0;
_AT_@ -108,7 +108,7 @@ addinput(char *fname, Symbol *hide)
                 fp = stdin;
                 fname = "<stdin>";
         }
- allocinput(fname, fp, NULL);
+ allocinput(fname, fp, buffer);
         input->hide = hide;
         input->nline = nline;
 
diff --git a/cc1/main.c b/cc1/main.c
index 83498e9..5531c19 100644
--- a/cc1/main.c
+++ b/cc1/main.c
_AT_@ -102,7 +102,7 @@ main(int argc, char *argv[])
         for (i = 0; i < uflags.n; ++i)
                 undefmacro(uflags.s[i]);
 
- if (!addinput(*argv, NULL)) {
+ if (!addinput(*argv, NULL, NULL)) {
                 die("error: failed to open input file '%s': %s",
                     *argv, strerror(errno));
         }
Received on Wed Jan 11 2017 - 16:53:20 CET

This archive was generated by hypermail 2.3.0 : Wed Jan 11 2017 - 17:00:21 CET