This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: PR preprocessor/30001


:ADDPATCH preprocessor:

This patch fixes PR preprocessor/30001.  This is an invalid memory
reference detected by valgrind.

I couldn't think of a way to test this other than by hand, so that is
what I did.

Built and regression tested on x86 FC5.

Ok?

Tom

2006-12-22  Tom Tromey  <tromey@redhat.com>

	PR preprocessor/30001:
	* charset.c (_cpp_convert_input): Check that to.len is greater
	than zero.

Index: charset.c
===================================================================
--- charset.c	(revision 120096)
+++ charset.c	(working copy)
@@ -1,5 +1,5 @@
 /* CPP Library - charsets
-   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004
+   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006
    Free Software Foundation, Inc.
 
    Broken out of c-lex.c Apr 2003, adding valid C99 UCN ranges.
@@ -1628,7 +1628,7 @@
      terminate with another \r, not an \n, so that we do not mistake
      the \r\n sequence for a single DOS line ending and erroneously
      issue the "No newline at end of file" diagnostic.  */
-  if (to.text[to.len - 1] == '\r')
+  if (to.len > 0 && to.text[to.len - 1] == '\r')
     to.text[to.len] = '\r';
   else
     to.text[to.len] = '\n';


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]