scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 9d9760579d87a8a5b22de85cd966ac57bfbc7e4d
parent e2a52562d6ba87fc4b4a82a75ae9bb992e8153a1
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 11 Jan 2017 16:19:29 +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().

Diffstat:
Mcc1/cc1.h | 2+-
Mcc1/cpp.c | 7+++----
Mcc1/lex.c | 4++--
Mcc1/main.c | 2+-
4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -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 @@ -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; } @@ -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 @@ -86,7 +86,7 @@ ilex(void) } int -addinput(char *fname, Symbol *hide) +addinput(char *fname, Symbol *hide, char *buffer) { FILE *fp; unsigned nline = 0; @@ -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 @@ -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)); }