diff mbox

[libgfortran,4.9/4.10,Regression] Erroneous "end of file" with internal read

Message ID 537FC837.1070105@charter.net
State New
Headers show

Commit Message

Jerry DeLisle May 23, 2014, 10:14 p.m. UTC
Hello all,

The attached patch fixes this PR by not seeking if the next character is a space.

Regression tested on x86-64.  New test case provided.

OK for trunk and back ports?

Regards.

Jerry

2014-05-23  Jerry DeLisle  <jvdelisle@gcc.gnu>

	PR libgfortran/61173
	* io/list_read.c (eat_spaces): If the next character pointed to
	is a space, don't seek, must be at the end.
diff mbox

Patch

Index: list_read.c
===================================================================
--- list_read.c	(revision 210879)
+++ list_read.c	(working copy)
@@ -398,7 +398,7 @@  eat_spaces (st_parameter_dt *dtp)
   if (is_array_io (dtp))
     {
       gfc_offset offset = stell (dtp->u.p.current_unit->s);
-      gfc_offset limit = dtp->u.p.current_unit->bytes_left;
+      gfc_offset limit = offset + dtp->u.p.current_unit->bytes_left;
 
       if (dtp->common.unit) /* kind=4 */
 	{
@@ -410,13 +410,15 @@  eat_spaces (st_parameter_dt *dtp)
 	      offset += (sizeof (gfc_char4_t));
 	      dtp->u.p.current_unit->bytes_left--;
 	    }
-	  while (offset < limit && (cc == (gfc_char4_t)' '
-		  || cc == (gfc_char4_t)'\t'));
+	  while (offset < limit && cc == (gfc_char4_t)' ');
 	  /* Back up, seek ahead, and fall through to complete the
 	     process so that END conditions are handled correctly.  */
 	  dtp->u.p.current_unit->bytes_left++;
-	  sseek (dtp->u.p.current_unit->s,
-		  offset-(sizeof (gfc_char4_t)), SEEK_SET);
+
+	  cc = dtp->internal_unit[offset];
+	  if (cc != (gfc_char4_t)' ')
+	    sseek (dtp->u.p.current_unit->s,
+		   offset-(sizeof (gfc_char4_t)), SEEK_SET);
 	}
       else
 	{
@@ -425,11 +427,13 @@  eat_spaces (st_parameter_dt *dtp)
 	      c = dtp->internal_unit[offset++];
 	      dtp->u.p.current_unit->bytes_left--;
 	    }
-	  while (offset < limit && (c == ' ' || c == '\t'));
+	  while (offset < limit && c == ' ');
 	  /* Back up, seek ahead, and fall through to complete the
 	     process so that END conditions are handled correctly.  */
 	  dtp->u.p.current_unit->bytes_left++;
-	  sseek (dtp->u.p.current_unit->s, offset-1, SEEK_SET);
+
+	  if (dtp->internal_unit[offset] != ' ')
+	    sseek (dtp->u.p.current_unit->s, offset - 1, SEEK_SET);
 	}
     }
   /* Now skip spaces, EOF and EOL are handled in next_char.  */