The attached patch fixes this problem by first reading the next available char
to see if EOF is encountered. If so, issue the EOF error. If not use eat_line
to find the end of the line. If the end of the line is at the end of the file,
it will be caught on any subsequent attempt to read.
The problem particularly manifests for empty reads that do no other actual file
reading except in (finish_list_read).
Regression tested on x86-64-linux-gnu. NIST tested. test case provided.
Ok for trunk?
Regards,
Jerry
2014-03-14 Jerry DeLisle jvdeli...@gcc.gnu
PR libfortran/58324
* io/list_read.c (finish_list_read): Read one character to check
for the end of the file. If it is the end, then issue the file
end error message. If not, use eat_line to reach the end
without giving error. The next attempt to read will then
issue the error as described above.
Index: list_read.c
===
--- list_read.c (revision 208561)
+++ list_read.c (working copy)
@@ -2092,8 +2092,6 @@ list_formatted_read (st_parameter_dt *dtp, bt type
void
finish_list_read (st_parameter_dt *dtp)
{
- int err;
-
free_saved (dtp);
fbuf_flush (dtp-u.p.current_unit, dtp-u.p.mode);
@@ -2106,13 +2104,20 @@ finish_list_read (st_parameter_dt *dtp)
if (!is_internal_unit (dtp))
{
- err = eat_line (dtp);
- if (err == LIBERROR_END)
+ int c;
+ c = next_char (dtp);
+ if (c == EOF)
{
free_line (dtp);
hit_eof (dtp);
+ return;
}
+ if (c != '\n')
+ eat_line (dtp);
}
+
+ free_line (dtp);
+
}
/* NAMELIST INPUT
! { dg-do run }
! PR58324 Bogus end of file condition
integer :: i, ios
open(99, access='stream', form='unformatted')
write(99) 5 a
close(99)
open(99, access='sequential', form='formatted')
read(99, *, iostat=ios) i
if (ios /= 0) call abort
end