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]

CPP: Memory corruption in gcc.dg/cpp/cmdlne-dM.c


realloc() was crashing while running cmdlne-dM.c.  The memory
corruption problem was fixed with the following patch.  Ok to install?

Index: gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* cppinit.c (cpp_cleanup): NULLify macro_buffer and zero
	macro_buffer_len.
	* cppmacro.c (cpp_macro_definition): Reset macro_buffer_len when
	realloc()ing macro_buffer.

Index: gcc/cppinit.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cppinit.c,v
retrieving revision 1.134
diff -u -p -r1.134 cppinit.c
--- gcc/cppinit.c 2001/01/08 18:52:09 1.134
+++ gcc/cppinit.c 2001/01/09 07:32:15
@@ -570,7 +570,11 @@ cpp_cleanup (pfile)
     cpp_pop_buffer (pfile);
 
   if (pfile->macro_buffer)
-    free ((PTR) pfile->macro_buffer);
+    {
+      free ((PTR) pfile->macro_buffer);
+      pfile->macro_buffer = NULL;
+      pfile->macro_buffer_len = 0;
+    }
 
   deps_free (pfile->deps);
 
Index: gcc/cppmacro.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cppmacro.c,v
retrieving revision 1.37
diff -u -p -r1.37 cppmacro.c
--- gcc/cppmacro.c 2000/12/17 22:40:32 1.37
+++ gcc/cppmacro.c 2001/01/09 07:32:15
@@ -1568,7 +1568,10 @@ cpp_macro_definition (pfile, node)
     }
 
   if (len > pfile->macro_buffer_len)
-    pfile->macro_buffer = (U_CHAR *) xrealloc (pfile->macro_buffer, len);
+    {
+      pfile->macro_buffer = (U_CHAR *) xrealloc (pfile->macro_buffer, len);
+      pfile->macro_buffer_len = len;
+    }
   buffer = pfile->macro_buffer;
 
   /* Parameter names.  */

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

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