[patch, libfortran] Fix for PR 19568, incorrect formatted read
Thomas Koenig
Thomas.Koenig@online.de
Mon Jan 31 21:21:00 GMT 2005
This is bubblestrapped and regtested on i686-pc-linux-gnu.
OK?
Thomas
2005-01-31 Thomas Koenig <Thomas.Koenig@online.de>
PR libfortran/19568
* io/transfer.c (read_sf): set buffer to blank instead of \0.
If there is an EOR condition, return the blanks.
* io/transfer.c (next_record_r): Reset sf_seen_eor when
advancing to the next record.
PR libfortran/19568
formatted_read_1.f90: New test file
-------------- next part --------------
Index: transfer.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/io/transfer.c,v
retrieving revision 1.31
diff -c -r1.31 transfer.c
*** transfer.c 29 Jan 2005 15:45:17 -0000 1.31
--- transfer.c 31 Jan 2005 21:13:00 -0000
***************
*** 150,156 ****
else
p = base = data;
! memset(base,'\0',*length);
current_unit->bytes_left = options.default_recl;
readlen = 1;
--- 150,161 ----
else
p = base = data;
! memset(base,' ',*length);
!
! /* If we have seen an end of record previously, just return blanks.
! */
! if (sf_seen_eor)
! return base;
current_unit->bytes_left = options.default_recl;
readlen = 1;
***************
*** 1223,1229 ****
length = 1;
/* sf_read has already terminated input because of an '\n' */
if (sf_seen_eor)
! break;
do
{
--- 1228,1237 ----
length = 1;
/* sf_read has already terminated input because of an '\n' */
if (sf_seen_eor)
! {
! sf_seen_eor = 0;
! break;
! }
do
{
-------------- next part --------------
! { dg-do run }
! PR 19568: We used to read past the end of a line
! Test case provided by gay@sfu.ca
program main
character(len=8) c1,c2
open(77)
write(77,'(A)') 'Line 1','Line 2','Line 3'
rewind(77)
read (77,'(A)') c1,c2
if (c2 .ne. 'Line 2') call abort
end program main
More information about the Gcc-patches
mailing list