This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, libgfortran] Fix bug triggered by NIST fm908.for - x-formattingbeyond eor during read
- From: Paul Thomas <paulthomas2 at wanadoo dot fr>
- To: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Sun, 10 Jul 2005 23:06:45 +0200
- Subject: [Patch, libgfortran] Fix bug triggered by NIST fm908.for - x-formattingbeyond eor during read
This one and its predecessor are inspired by Jerry DeLisle noting that
we are very close to getting a clean sweep in NIST. The namelist work
brought me into close proximity to these corners.
The bug is due to a runtime error occurring when x-formatting during
read goes beyond the end of record. The fix is very simple and the
patch speaks for itself. The testcase is drawn from fm908.for
Regtested on RH9 and Athlon.
OK for 4.1?
Paul T
2005-07-10 Paul Thomas <pault@gcc.gnu.org>
* read.c (read_complex): Prevent X formatting during reads
from going beyond EOR to fix NIST fm908.for failure.
2005-07-10 Paul Thomas <pault@gcc.gnu.org>
* gfortran.dg/past_eor.f90: New.
Index: gcc/libgfortran/io/read.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/read.c,v
retrieving revision 1.12
diff -c -3 -p -r1.12 read.c
*** gcc/libgfortran/io/read.c 23 Jun 2005 18:50:24 -0000 1.12
--- gcc/libgfortran/io/read.c 10 Jul 2005 20:55:01 -0000
*************** read_x (fnode * f)
*** 767,771 ****
int n;
n = f->u.n;
! read_block (&n);
}
--- 767,775 ----
int n;
n = f->u.n;
! if (f->format == FMT_X)
! n = (n > (int)current_unit->bytes_left)
! ? (int)current_unit->bytes_left : n;
! if (n)
! read_block (&n);
}
!===================================================================
! { dg-do run }
! Test of the fix to the bug triggered by NIST fm908.for.
! Contributed by Paul Thomas <pault@gcc.gnu.org>
!
program past_eor
character(len=82) :: buffer
real :: a(2), b(2), c(2), d(2), e(2)
e = (/2.34,2.456/)
! tests 28-31 from fm908.for
buffer = ' 2.34 , 2.456 2.34 , 2.456 0.234E01, 2.456E00&
& 0.234E+001, 2.456E-000'
READ (UNIT=buffer,FMT=10) a, b, c, d
10 FORMAT (2(2(G7.5,1X),2X),2(G10.4E2,1X),1X,2(G11.7E4,1X))
if (any (a.ne.e).or.any (b.ne.e).or.any (c.ne.e).or.any (d.ne.e)) call abort ()
end program past_eor