This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: gfortran patch for PR 18778 Abort on endfile on unopened unit
- From: Bud Davis <bdavis9659 at comcast dot net>
- To: Paul Brook <paul at codesourcery dot com>
- Cc: gfortran <fortran at gcc dot gnu dot org>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 31 Dec 2004 19:50:29 -0600
- Subject: Re: gfortran patch for PR 18778 Abort on endfile on unopened unit
- References: <1103859364.30627.12.camel@localhost.localdomain> <200412271436.28000.paul@codesourcery.com>
On Mon, 2004-12-27 at 08:36, Paul Brook wrote:
> > 2004-12-23 Bud Davis <bdavis9659@comcast.net>
> >
> > PR fortran/18778
> > * io/transfer.c (us_read): no bytes available is not a
> > runtime error.
> > * io/endfile.c (st_endfile): open the unit if needed.
>
> > Index: gcc/libgfortran/io/endfile.c
> > ===================================================================
> > ! /* endfile without an open on this unit.
> > ! not an error, so let's make a unit
> > ! */
> > ! memset (&u_flags, '\0', sizeof (u_flags));
> > ! u_flags.access = ACCESS_SEQUENTIAL;
> > ! u_flags.action = ACTION_READWRITE;
> > ! u_flags.form = FORM_UNFORMATTED;
>
> Why not *_UNSPECIFIED here?
>
> Other than that, Ok.
>
> Paul
upon closer reflection, endfile on an un-opened unit is ignored just
fine.... { note to self, find the problem before you fix it :) }
the patch below fixes the problem:
RCS file: /cvs/gcc/gcc/libgfortran/io/transfer.c,v
retrieving revision 1.23
diff -c -3 -p -r1.23 transfer.c
*** gcc/libgfortran/io/transfer.c 24 Dec 2004 00:29:07 -0000 1.23
--- gcc/libgfortran/io/transfer.c 24 Dec 2004 03:23:05 -0000
*************** us_read (void)
*** 834,839 ****
--- 834,842 ----
n = sizeof (gfc_offset);
p = salloc_r (current_unit->s, &n);
+ if (n == 0)
+ return; /* end of file */
+
if (p == NULL || n != sizeof (gfc_offset))
{
generate_error (ERROR_BAD_US, NULL);
changelog same, testsuite file same, results same.
--bud