ref: 5d7ab730e604765f4ac4327d05dce79d257030d3
parent: f236a23b80e74546c6c5dc68bfce7fad59dc320c
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Jan 11 11:19:29 EST 2017
[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().
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -394,7 +394,7 @@
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);
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -267,10 +267,9 @@
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 @@
memcpy(path+dirlen, file, filelen);
path[dirlen + filelen] = '\0';
- return addinput(path, NULL);
+ return addinput(path, NULL, NULL);
}
static void
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -86,7 +86,7 @@
}
int
-addinput(char *fname, Symbol *hide)
+addinput(char *fname, Symbol *hide, char *buffer)
{
FILE *fp;
unsigned nline = 0;
@@ -108,7 +108,7 @@
fp = stdin;
fname = "<stdin>";
}
- allocinput(fname, fp, NULL);
+ allocinput(fname, fp, buffer);
input->hide = hide;
input->nline = nline;
--- a/cc1/main.c
+++ b/cc1/main.c
@@ -102,7 +102,7 @@
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));
}