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, libfortran] PR35132 Formatted stream I/O write should truncate


This patch is obvious and simple. I will commit as soon as 4.4 opens. Sooner if others are insisting.

Regression tested on x86-64-Linux. New test case from the PR.

Jerry

2008-02-09 Jerry DeLisle <jvdelisle@gcc.gnu.org>

	PR libfortran/35132
	* io/transfer.c (next_record_w): When WRITE, truncate after
	the last record for STREAM I/O.
Index: transfer.c
===================================================================
--- transfer.c	(revision 132079)
+++ transfer.c	(working copy)
@@ -2594,7 +2594,10 @@ next_record_w (st_parameter_dt *dtp, int
 	    goto io_error;
 	  
 	  if (is_stream_io (dtp))
-	    dtp->u.p.current_unit->strm_pos += len;
+	    {
+	      dtp->u.p.current_unit->strm_pos += len;
+	      struncate(dtp->u.p.current_unit->s);
+	    }
 	}
 
       break;
! { dg-do run }
! PR35132 Formatted stream I/O write should truncate.
! Test case adapted from PR by Jerry DeLisle  <jvdelisle@gcc.gnu.org>
program main
  implicit none
  character(len=6) :: c
  integer :: i
  open(20,file="foo.txt",form="formatted",access="stream")
  write(20,'(A)') '123456'
  write(20,'(A)') 'abcdef'
  write(20,'(A)') 'qwerty'
  rewind 20
  ! Skip over the first line
  read(20,'(A)') c
  if (c.ne.'123456') call abort
  ! Save the position
  inquire(20,pos=i)
  if (i.ne.8) call abort
  ! Read in the complete line...
  read(20,'(A)') c
  if (c.ne.'abcdef') call abort
  ! Write out the first four characters
  write(20,'(A)',pos=i,advance="no") 'ASDF'
  ! Fill up the rest of the line.  Here, we know the length.  If we
  ! don't, things will be a bit more complicated.
  write(20,'(A)') c(5:6)
  ! Copy the file to standard output
  rewind 20
  c = ""
  read(20,'(A)') c
  if (c.ne.'123456') call abort
  read(20,'(A)') c
  if (c.ne.'ASDFef') call abort
  read(20,'(A)', iostat=i) c
  if (i /= -1) call abort
  close (20, status="delete")
end program main

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