This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix for a cpp0 segfault on bad command line option
- To: gcc-patches at gcc dot gnu dot org
- Subject: [PATCH] Fix for a cpp0 segfault on bad command line option
- From: Sean Woolcock <sean_woolcock99 at yahoo dot com>
- Date: Thu, 24 May 2001 18:48:18 -0700 (PDT)
- Reply-To: catullus at users dot sourceforge dot net
Hi,
Thanks for gcc!
Here's a bug:
$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
$ rm -f hello.c; touch hello.c
$ gcc -D- hello.c
<command line>: macro names must be identifiers
gcc: Internal error: Segmentation fault (program cpp0)
Please submit a full bug report.
See <URL:http://bugzilla.redhat.com/bugzilla/> for instructions.
Any invalid identifier after -D seems to do the trick.
Here's the guilty call path:
#0 check_eol (pfile=0x8062860) at ../../gcc/cpplib.c:212
#1 0x0804a363 in run_directive (pfile=0x8062860, dir_no=0,
type=BUF_CL_OPTION, buf=0xbffff6a0 "- 1¿1)\"\n", count=3)
at ../../gcc/cpplib.c:403
#2 0x0804c1b9 in cpp_define (pfile=0x8062860, str=0xbffff989 "-")
at ../../gcc/cpplib.c:1660
#3 0x08055e68 in cpp_start_read (pfile=0x8062860,
fname=0xbffff98b "/home/sean/dl/gcc/hello.c") at
../../gcc/cppinit.c:929
#4 0x080496a3 in do_preprocessing ()
#5 0x0804951d in main ()
#6 0x4003e237 in __libc_start_main () from /lib/libc.so.6
Here are the guilty lines (sorta), in gcc/cpplib.c:check_eol():
if (token.type != CPP_EOF)
cpp_pedwarn (pfile, "extra tokens at end of #%s directive",
pfile->directive->name);
pfile->directive comes in NULL with the above command line. I say sorta,
since the real bug is probably somewhere that doesn't set pfile->directive
properly. I didn't see that spot right away.
Here's a patch for the immediate problem:
===========================================================================
--- gcc/cpplib.c.orig Thu May 24 20:57:05 2001
+++ gcc/cpplib.c Thu May 24 21:12:34 2001
@@ -210,7 +210,8 @@
cpp_token token;
_cpp_lex_token (pfile, &token);
- if (token.type != CPP_EOF)
+ if (token.type != CPP_EOF
+ && pfile->directive != NULL)
cpp_pedwarn (pfile, "extra tokens at end of #%s directive",
pfile->directive->name);
}
===========================================================================
Sean
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/