This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix tradcpp -include bug
- To: gcc-patches at gcc dot gnu dot org
- Subject: [PATCH] Fix tradcpp -include bug
- From: Franz Sirl <Franz dot Sirl-kernel at lauterbach dot com>
- Date: Wed, 3 Jan 2001 16:02:26 +0100
Hi,
compiling glibc-2.2 on powerpc-linux-gnu with current mainline exposed a bug
in tradcpp's -include handling, it called finclude() with indepth==-1 and
corrupted arbitrary memory while accessing instack[indepth]. This caused a
null character to be output, confusing later processing in glibc.
I could reproduce the bug with a testcase as simple as:
touch test1 test2
gcc -traditional -E -undef -include ./test1 -x c ./test2 >murx
The attached Patch fixes it, OK to commit?
The output after the patch still misses the #line directives, but I think
it's no goal to make this work for tradcpp?
Franz.
* tradcpp.c (main): Make sure finclude() is called with a valid
indepth value while handling -include.
Index: gcc/tradcpp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tradcpp.c,v
retrieving revision 1.27
diff -u -p -r1.27 tradcpp.c
--- gcc/tradcpp.c 2000/12/16 10:41:56 1.27
+++ gcc/tradcpp.c 2001/01/03 14:41:15
@@ -768,6 +768,7 @@ main (argc, argv)
so that only their macro definitions matter. */
no_output++;
+ indepth++;
for (i = 1; i < argc; i++)
if (pend[i].type == PD_FILE)
{
@@ -779,6 +780,7 @@ main (argc, argv)
}
finclude (fd, pend[i].arg, &outbuf);
}
+ indepth--;
no_output--;
/* Pending directives no longer needed. */