This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[3.2 PATCH] Fix PR preprocessor/9465
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 1 Feb 2003 22:51:36 +0100
- Subject: [3.2 PATCH] Fix PR preprocessor/9465
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
fixup_newlines segfaults when '\0' occurs before first '\r' in the file
(strchr returns NULL and it later on dereferences it).
Gaby, is this ok for 3.2 branch (tradcpp.c was removed for 3.3+, so it is
3.2 branch patch only)?
2003-02-01 Jakub Jelinek <jakub@redhat.com>
PR preprocessor/9465
* tradcpp.c (fixup_newlines): Use memchr instead of strchr.
--- gcc/tradcpp.c.jj 2002-11-12 12:19:10.000000000 -0500
+++ gcc/tradcpp.c 2003-02-01 15:59:57.000000000 -0500
@@ -1,5 +1,5 @@
/* C Compatible Compiler Preprocessor (CCCP)
-Copyright (C) 1986, 1987, 1989, 2000, 2001 Free Software Foundation, Inc.
+Copyright (C) 1986, 1987, 1989, 2000, 2001, 2003 Free Software Foundation, Inc.
Written by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
Dusted off, polished, and adapted for use as traditional
@@ -2604,10 +2604,8 @@ fixup_newlines (fp)
return;
end = fp->buf + fp->length;
- *end = '\r';
- p = (U_CHAR *) strchr ((const char *) fp->buf, '\r');
- *end = '\0';
- if (p == end)
+ p = (U_CHAR *) memchr ((const char *) fp->buf, '\r', fp->length);
+ if (p == NULL)
return;
if (p > fp->buf && p[-1] == '\n')
Jakub