]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/41328 (bad iostat when reading DOS file in a character array (non-advan...
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Sun, 13 Sep 2009 03:41:41 +0000 (03:41 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Sun, 13 Sep 2009 03:41:41 +0000 (03:41 +0000)
2009-09-12  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

PR libgfortran/41328
* io/transfer.c (read_sf): Adjust fbuf position and do proper
fbuf reads to traverse CR, CR-LF, and LF style line ends.

From-SVN: r151665

libgfortran/ChangeLog
libgfortran/io/transfer.c

index 1b2e96150a31f2f49de87b3091400eb3e8540830..346981415f10bb9921fa9670e66837457d743973 100644 (file)
@@ -1,3 +1,9 @@
+2009-09-12  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR libgfortran/41328
+       * io/transfer.c (read_sf): Adjust fbuf position and do proper
+       fbuf reads to traverse CR, CR-LF, and LF style line ends.
+
 2009-09-12  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libgfortran/41219
index 59f88d4fb9bb862f1f0b23bd4ffb62c1cf66dadb..2362a1545929246306be363f23d806bb046c6dcb 100644 (file)
@@ -232,21 +232,28 @@ read_sf (st_parameter_dt *dtp, int * length, int no_error)
 
       if (q == '\n' || q == '\r')
        {
-         /* Unexpected end of line.  */
+         /* Unexpected end of line. Set the position.  */
+         fbuf_seek (dtp->u.p.current_unit, n + 1 ,SEEK_CUR);
+         dtp->u.p.sf_seen_eor = 1;
 
          /* If we see an EOR during non-advancing I/O, we need to skip
             the rest of the I/O statement.  Set the corresponding flag.  */
          if (dtp->u.p.advance_status == ADVANCE_NO || dtp->u.p.seen_dollar)
            dtp->u.p.eor_condition = 1;
-
+           
          /* If we encounter a CR, it might be a CRLF.  */
          if (q == '\r') /* Probably a CRLF */
            {
-             if (n < *length && *(p + 1) == '\n')
-               dtp->u.p.sf_seen_eor = 2;
+             /* See if there is an LF. Use fbuf_read rather then fbuf_getc so
+                the position is not advanced unless it really is an LF.  */
+             int readlen = 1;
+             p = fbuf_read (dtp->u.p.current_unit, &readlen);
+             if (*p == '\n' && readlen == 1)
+               {
+                 dtp->u.p.sf_seen_eor = 2;
+                 fbuf_seek (dtp->u.p.current_unit, 1 ,SEEK_CUR);
+               }
            }
-          else
-            dtp->u.p.sf_seen_eor = 1;
 
          /* Without padding, terminate the I/O statement without assigning
             the value.  With padding, the value still needs to be assigned,
@@ -260,7 +267,7 @@ read_sf (st_parameter_dt *dtp, int * length, int no_error)
            }
 
          *length = n;
-         break;
+         goto done;
        }
       /*  Short circuit the read if a comma is found during numeric input.
          The flag is set to zero during character reads so that commas in
@@ -274,13 +281,11 @@ read_sf (st_parameter_dt *dtp, int * length, int no_error)
            *length = n;
            break;
          }
-
       n++;
       p++;
     } 
 
-  fbuf_seek (dtp->u.p.current_unit, n + dtp->u.p.sf_seen_eor + seen_comma, 
-             SEEK_CUR);
+  fbuf_seek (dtp->u.p.current_unit, n + seen_comma, SEEK_CUR);
 
   /* A short read implies we hit EOF, unless we hit EOR, a comma, or
      some other stuff. Set the relevant flags.  */