diff mbox

[libfortran] PR 49296 List read of file without EOR

Message ID BANLkTi=aX=B9tDAQVtVc_bB43CxsY4aJdw@mail.gmail.com
State New
Headers show

Commit Message

Janne Blomqvist June 11, 2011, 10:05 a.m. UTC
Hi,

attached patch fixes PR 49296. A new test for the testsuite is also included.

Regtested on x86_64-unknown-linux-gnu, Ok for trunk?

2011-06-11  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libfortran/49296
	* io/list_read.c (read_character): Accept EOF as a separator when
	reading string.

Comments

Janne Blomqvist June 17, 2011, 7:02 p.m. UTC | #1
PING.

Also, here's a slightly simplfied testcase:

! { dg-do run }
! PR 49296 List formatted read of file without EOR marker (\n).
program read_list_eof_1
  implicit none
  character(len=100) :: s
  call genfil ()
  open (unit=20, file='read.dat', form='FORMATTED', action='READ', &
       status='OLD')
  read (20, fmt=*) s
  close (20, status='delete')
  if (trim(s) /= "a") then
     call abort ()
  end if

contains
  subroutine genfil
    open(10, file='read.dat', form='unformatted', action='write', &
         status='replace', access='stream')
    write(10) 'a'
    close(10)
  end subroutine genfil
end program read_list_eof_1


On Sat, Jun 11, 2011 at 13:05, Janne Blomqvist
<blomqvist.janne@gmail.com> wrote:
> Hi,
>
> attached patch fixes PR 49296. A new test for the testsuite is also included.
>
> Regtested on x86_64-unknown-linux-gnu, Ok for trunk?
>
> 2011-06-11  Janne Blomqvist  <jb@gcc.gnu.org>
>
>        PR libfortran/49296
>        * io/list_read.c (read_character): Accept EOF as a separator when
>        reading string.
>
>
> --
> Janne Blomqvist
>
Jerry DeLisle June 18, 2011, 12:18 a.m. UTC | #2
On 06/17/2011 12:02 PM, Janne Blomqvist wrote:
> PING.
>
> Also, here's a slightly simplfied testcase:
>
Yes, OK

Jerry
diff mbox

Patch

diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c
index 38a92e1..baf2f54 100644
--- a/libgfortran/io/list_read.c
+++ b/libgfortran/io/list_read.c
@@ -1022,7 +1022,7 @@  read_character (st_parameter_dt *dtp, int length __attribute__ ((unused)))
   for (;;)
     {
       if ((c = next_char (dtp)) == EOF)
-	goto eof;
+	goto done_eof;
       switch (c)
 	{
 	case '"':
@@ -1068,26 +1068,26 @@  read_character (st_parameter_dt *dtp, int length __attribute__ ((unused)))
      invalid.  */
  done:
   c = next_char (dtp);
- eof:
-  if (is_separator (c) || c == '!')
+ done_eof:
+  if (is_separator (c) || c == '!' || c == EOF)
     {
       unget_char (dtp, c);
       eat_separator (dtp);
       dtp->u.p.saved_type = BT_CHARACTER;
       free_line (dtp);
     }
-  else
+  else 
     {
       free_saved (dtp);
-      if (c == EOF)
-	{
-	  hit_eof (dtp);
-	  return;
-	}
       snprintf (message, MSGLEN, "Invalid string input in item %d",
 		  dtp->u.p.item_count);
       generate_error (&dtp->common, LIBERROR_READ_VALUE, message);
     }
+  return;
+
+ eof:
+  free_saved (dtp);
+  hit_eof (dtp);
 }