This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[patch, libgfortran] PR32678 GFortan works incorrectly when writing with FORMAT Tx
- From: Jerry DeLisle <jvdelisle at verizon dot net>
- To: Fortran List <fortran at gcc dot gnu dot org>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 08 Jul 2007 16:34:27 -0700
- Subject: [patch, libgfortran] PR32678 GFortan works incorrectly when writing with FORMAT Tx
I will commit this patch as obvious and simple, though OKed by Thomas on IRC.
In testing this we did not find any compiler that did not insert NULLs somewhere
in the string when they should not for the test case.
This patch fixes this for gfortran.
The test case does a byte for byte test on the results using stream I/O. Very
convenient for this sort of thing which could only be seen by hex dump of the
output.
Regression tested on x86-64-Gnu/Linux.
Test case attached.
Regards,
Jerry
2007-07-09 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/32678
* io/transfer.c (formatted_transfer_scalar): Don't allow pending_spaces
to go negative.
Index: transfer.c
===================================================================
--- transfer.c (revision 126449)
+++ transfer.c (working copy)
@@ -1213,6 +1213,8 @@ formatted_transfer_scalar (st_parameter_
dtp->u.p.skips = dtp->u.p.skips + pos - bytes_used;
dtp->u.p.pending_spaces = dtp->u.p.pending_spaces
+ pos - dtp->u.p.max_pos;
+ dtp->u.p.pending_spaces = dtp->u.p.pending_spaces < 0
+ ? 0 : dtp->u.p.pending_spaces;
if (dtp->u.p.skips == 0)
break;
! { dg-do run }
! PR32678 GFortan works incorrectly when writing with FORMAT Tx
! Before patch, NULLs were inserted in output.
! Test case from reporter enhanced to detect this problem.
character(25) :: output
character(1) :: c
output = ""
open (unit=10, file="pr32678testfile", status="replace")
write (10,10) '12','a','b'
close (10, status="keep")
open (unit=10, file="pr32678testfile", access="stream")
read(10, pos=1) output(1:21)
if (output(1:21).ne."ab x") call abort
read(10) c
if (c.ne.achar(10)) call abort
close (10, status="delete")
10 format (a2,t1,a1,t2,a1,t20,' x')
end