While exploring an unrelated bug (32702) I rearranged the unix_stream structure
in libgfortran/io/unix.c as shown below.  This results in a segfault with
streamio_3.f90.  Valgrind reports and invalid write of 1.  With further
experimentation I can add 1 to the pointer returned by fd_alloc_w_at and I can
get the fault to artificially go away and valgrind to report no errors. 
However, this does not actually eliminate the problem.

I am still pursuing this.  In the meantime, the problem does not manifest with
current trunk as far as I can tell and valgrind reports clean.  I am submitting
this report to track that something is wrong here and I am trying to fix it.

Note that all that I am doing is moving the location of the buffer pointer. 
This manifests the problem.  If I stick a pad integer between buffer and
small_buffer within the structure, the problem no longer manifests.  I suspect
we are trashing the buffer pointer.

Index: unix.c
===================================================================
--- unix.c      (revision 126610)
+++ unix.c      (working copy)
@@ -97,7 +97,6 @@ typedef struct
   gfc_offset dirty_offset;     /* Start of modified bytes in buffer */
   gfc_offset file_length;      /* Length of the file, -1 if not seekable. */

-  char *buffer;
   int len;                     /* Physical length of the current buffer */
   int active;                  /* Length of valid bytes in the buffer */

@@ -108,6 +107,7 @@ typedef struct

   int unbuffered;               /* =1 if the stream is not buffered */

+  char *buffer;
   char small_buffer[BUFFER_SIZE];
 }
 unix_stream;


-- 
           Summary: Segfault on WRITE with modified unix_stream structure
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
        AssignedTo: jvdelisle at gcc dot gnu dot org
        ReportedBy: jvdelisle at gcc dot gnu dot org
  GCC host triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32752

Reply via email to