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] Fix PR preprocessor/15167


Hi,

This is a regression on the mainline and 3.4 branch related to #pragma once.  
The compiler segfaults when a #pragma-onced header is included from two 
different directories (e.g. parent and child directory).

The segfault occurs because f->buffer is NULL when memcmp is invoked in 
should_stack_file here

      if ((import || f->once_only)
	  && f->err_no == 0
	  && f->st.st_mtime == file->st.st_mtime
	  && f->st.st_size == file->st.st_size
	  && read_file (pfile, f)
	  /* Size might have changed in read_file().  */
	  && f->st.st_size == file->st.st_size
	  && !memcmp (f->buffer, file->buffer, f->st.st_size))
	break;

although read_file was invoked on f.  The problem originates in 
_cpp_pop_file_buffer, which doesn't reset f->buffer_valid.

Bootstrapped/regtested on amd64-mandrake-linux-gnu.  No testcase because it is 
made up of 5 files.  OK for mainline and 3.4 branch?


2004-12-05  Eric Botcazou  <ebotcazou@libertysurf.fr>

	PR preprocessor/15167
	* files.c (_cpp_pop_file_buffer): Set buffer_valid to false.


2004-12-05  Eric Botcazou  <ebotcazou@libertysurf.fr>

	PR preprocessor/15167
	* cppfiles.c (_cpp_pop_file_buffer): Set buffer_valid to false.


-- 
Eric Botcazou
Index: files.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/files.c,v
retrieving revision 1.5
diff -u -p -r1.5 files.c
--- files.c	16 Jul 2004 17:07:01 -0000	1.5
+++ files.c	5 Dec 2004 18:31:08 -0000
@@ -1124,6 +1124,7 @@ _cpp_pop_file_buffer (cpp_reader *pfile,
     {
       free ((void *) file->buffer);
       file->buffer = NULL;
+      file->buffer_valid = false;
     }
 }
 
Index: cppfiles.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/cppfiles.c,v
retrieving revision 1.198.4.3
diff -u -p -r1.198.4.3 cppfiles.c
--- cppfiles.c	16 Jul 2004 17:16:43 -0000	1.198.4.3
+++ cppfiles.c	5 Dec 2004 09:47:58 -0000
@@ -1033,6 +1033,7 @@ _cpp_pop_file_buffer (cpp_reader *pfile,
     {
       free ((void *) file->buffer);
       file->buffer = NULL;
+      file->buffer_valid = false;
     }
 }
 

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