re PR libfortran/80727 (Crash of runtime gfortran library during integer transformation)
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Mon, 15 May 2017 23:48:39 +0000 (23:48 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Mon, 15 May 2017 23:48:39 +0000 (23:48 +0000)
2017-05-15  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

PR libgfortran/80727
* transfer.c (read_sf_internal): Remove bogus code to detect EOR.
(read_block_form): For internal units, generate EOR if no more
bytes left in unit and we are trying to read with ADVANCE='NO'.

* gfortran.dg/read_3.f90: New test.

From-SVN: r248080

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/read_3.f90 [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/io/transfer.c

index a8985227a2f9c3313fda3c6f986f35a7b3a72ab0..1aceb818d9d74c7f7e146d53c4feeef4673f931c 100644 (file)
@@ -1,3 +1,8 @@
+2017-05-15  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR libgfortran/80727
+       * gfortran.dg/read_3.f90: New test.
+
 2017-05-15  Nathan Sidwell  <nathan@acm.org>
 
        PR c++/79369
diff --git a/gcc/testsuite/gfortran.dg/read_3.f90 b/gcc/testsuite/gfortran.dg/read_3.f90
new file mode 100644 (file)
index 0000000..630666e
--- /dev/null
@@ -0,0 +1,13 @@
+! { dg-do run }
+! PR80727 Crash of runtime gfortran library during integer transformation
+! Note: before the patch this was giving an incorrect EOR error on READ.
+program    gfortran_710_io_bug
+  character  str*4
+  integer(4) :: i4
+  str =''
+  i = 256
+  write(str,fmt='(a)') i
+  i = 0
+  read ( unit=str(1:4), fmt='(a)' ) i4
+  if (i4.ne.256) call abort
+end  program  gfortran_710_io_bug 
index 8a5d8033f2ceef1d2f782859572601465d4d57db..b604147ffee29d3f375e88d6df012bbcd91e5865 100644 (file)
@@ -1,3 +1,10 @@
+2017-05-15  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR libgfortran/80727
+       * transfer.c (read_sf_internal): Remove bogus code to detect EOR.
+       (read_block_form): For internal units, generate EOR if no more
+       bytes left in unit and we are trying to read with ADVANCE='NO'.
+
 2017-05-15  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/80765
index f16d8c55f6d01d130d2f87d10bf6c87a2e845ed6..928a448f74cf93121dc4e09912f023b20b094e51 100644 (file)
@@ -272,12 +272,6 @@ read_sf_internal (st_parameter_dt *dtp, int *length)
       return NULL;
     }
 
-  if (base && *base == 0)
-    {
-      generate_error (&dtp->common, LIBERROR_EOR, NULL);
-      return NULL;
-    }
-
   dtp->u.p.current_unit->bytes_left -= *length;
 
   if (((dtp->common.flags & IOPARM_DT_HAS_SIZE) != 0) ||
@@ -470,11 +464,24 @@ read_block_form (st_parameter_dt *dtp, int *nbytes)
                }
            }
 
-         if (unlikely (dtp->u.p.current_unit->bytes_left == 0
-             && !is_internal_unit(dtp)))
+         if (is_internal_unit(dtp))
            {
-             hit_eof (dtp);
-             return NULL;
+             if (*nbytes > 0 && dtp->u.p.current_unit->bytes_left == 0)
+               {
+                 if (dtp->u.p.advance_status == ADVANCE_NO)
+                   {
+                     generate_error (&dtp->common, LIBERROR_EOR, NULL);
+                     return NULL;
+                   }
+               }
+           }
+         else
+           {
+             if (unlikely (dtp->u.p.current_unit->bytes_left == 0))
+               {
+                 hit_eof (dtp);
+                 return NULL;
+               }
            }
 
          *nbytes = dtp->u.p.current_unit->bytes_left;