]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR fortran/77707 (formatted direct access: nextrec off by one)
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Fri, 30 Sep 2016 04:49:36 +0000 (04:49 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Fri, 30 Sep 2016 04:49:36 +0000 (04:49 +0000)
2016-09-29  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

Backport from trunk
PR libgfortran/77707
io/transfer.c (next_record): Flush before calculating next_record.
Correctly calculate.

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

From-SVN: r240645

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

index ee9d5f5869d351f553f6696b65af23723b0b81d2..96e4718e8a843e5dce8447b61107a5e2aa0949e2 100644 (file)
@@ -1,3 +1,9 @@
+2016-09-29  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       Backport from trunk
+       PR libgfortran/77707
+       * gfortran.dg/inquire_17.f90: New test.
+
 2016-09-29  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        Backport from trunk
diff --git a/gcc/testsuite/gfortran.dg/inquire_17.f90 b/gcc/testsuite/gfortran.dg/inquire_17.f90
new file mode 100644 (file)
index 0000000..8a722f0
--- /dev/null
@@ -0,0 +1,10 @@
+! { dg-do run }
+! PR77707 formatted direct access: nextrec off by one
+program directaccess_formatted
+  integer nextrec
+  open(10, status='scratch', form='formatted', access='direct', recl=10*4)
+  write(10,'(10i4)',rec=9) 1,2,3,4,5,6,7,8,9,10
+  inquire(unit=10,nextrec=nextrec)
+  if (nextrec.ne.10) call abort
+  close(10)
+end
index 5d310d42d14c7b05167985a414a3478d68edb026..9048779f8538998614c0547947758ecd15c40e27 100644 (file)
@@ -1,3 +1,10 @@
+2016-09-29  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       Backport from trunk
+       PR libgfortran/77707
+       io/transfer.c (next_record): Flush before calculating next_record.
+       Correctly calculate.
+
 2016-09-29  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        Backport from trunk
index 746bb6dcc6cc4f3aa64f6410808383835b344322..f49052c8a622b998ca95486923365ba9fd08780e 100644 (file)
@@ -3502,6 +3502,8 @@ next_record (st_parameter_dt *dtp, int done)
   else
     next_record_w (dtp, done);
 
+  fbuf_flush (dtp->u.p.current_unit, dtp->u.p.mode);
+
   if (!is_stream_io (dtp))
     {
       /* Since we have changed the position, set it to unspecified so
@@ -3515,8 +3517,8 @@ next_record (st_parameter_dt *dtp, int done)
          fp = stell (dtp->u.p.current_unit->s);
          /* Calculate next record, rounding up partial records.  */
          dtp->u.p.current_unit->last_record =
-           (fp + dtp->u.p.current_unit->recl - 1) /
-             dtp->u.p.current_unit->recl;
+           (fp + dtp->u.p.current_unit->recl) /
+             dtp->u.p.current_unit->recl - 1;
        }
       else
        dtp->u.p.current_unit->last_record++;
@@ -3525,7 +3527,6 @@ next_record (st_parameter_dt *dtp, int done)
   if (!done)
     pre_position (dtp);
 
-  fbuf_flush (dtp->u.p.current_unit, dtp->u.p.mode);
   smarkeor (dtp->u.p.current_unit->s);
 }