]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR libfortran/92100 (Formatted stream IO irreproducible read with binary...
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Tue, 26 Nov 2019 22:56:24 +0000 (22:56 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Tue, 26 Nov 2019 22:56:24 +0000 (22:56 +0000)
2019-11-26  Jerry DeLisle  <jvdelisle@gcc.ngu.org>

        Backport from mainline
        PR fortran/92100
        io/transfer.c (data_transfer_init_worker): Use fbuf_reset
        instead of fbuf_flush before the seek. Note that fbuf_reset
        calls fbuf_flush and adjusts fbuf pointers.

        gfortran.dg/streamio_18.f90: New test.

From-SVN: r278740

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

index c07ef85ce92741f93b2a00435cc215a32d8a79bf..2ec93f884c796ab3f1d17ecf60d306969f82caa4 100644 (file)
@@ -1,3 +1,9 @@
+2019-11-26  Jerry DeLisle  <jvdelisle@gcc.ngu.org>
+
+       Backport from trunk
+       PR fortran/92100
+       gfortran.dg/streamio_18.f90: New test.
+
 2019-11-25  Thomas Koenig  <tkoenig@gcc.gnu.org>
        Harald Anlauf <anlauf@gmx.de>
 
diff --git a/gcc/testsuite/gfortran.dg/streamio_18.f90 b/gcc/testsuite/gfortran.dg/streamio_18.f90
new file mode 100644 (file)
index 0000000..ee36238
--- /dev/null
@@ -0,0 +1,23 @@
+! { dg-do run }
+! PR91200
+program foo
+  implicit none
+  integer fd
+  open(newunit=fd, file='test.dat', access='stream', form='formatted')
+  write(fd,'(A)') '$MeshFormat'
+  write(fd,'(A)') 'aabbccdd'
+  close(fd)
+  call readfile  ! Read test.dat
+contains
+  subroutine readfile
+     character(len=20) buf1, buf2
+     integer fd, m, n
+     open(newunit=fd, file='test.dat', access='stream', form='formatted')
+     inquire(fd, pos=m)
+     if (m /= 1) stop 'm /= 1'
+     read(fd, *) buf1
+     read(fd, *, pos=m) buf2        ! Reread by using pos=1
+     close(fd, status='delete')
+     if (buf1 /= buf2) stop 'wrong'
+  end subroutine readfile
+end program
index 5bf3cc8340d2bc4b6eca3b51915360163f103ac6..34ca3548589fad6a95f7646f2bdfd24a7e8c9ef7 100644 (file)
@@ -1,3 +1,11 @@
+2019-11-26  Jerry DeLisle  <jvdelisle@gcc.ngu.org>
+
+        Backport from mainline
+        PR fortran/92100
+        io/transfer.c (data_transfer_init_worker): Use fbuf_reset
+        instead of fbuf_flush before the seek. Note that fbuf_reset
+        calls fbuf_flush and adjusts fbuf pointers.
+
 2019-11-25  Thomas Koenig  <tkoenig@gcc.gnu.org>
        Harald Anlauf <anlauf@gmx.de>
 
index 8ed0391225d194d737d98195fe3e9ef67baa2de4..28e403fedf2f7ad8ba4662e0b4052a68a628e82b 100644 (file)
@@ -3294,8 +3294,9 @@ data_transfer_init_worker (st_parameter_dt *dtp, int read_flag)
 
           if (dtp->pos != dtp->u.p.current_unit->strm_pos)
             {
-              fbuf_flush (dtp->u.p.current_unit, dtp->u.p.mode);
-              if (sseek (dtp->u.p.current_unit->s, dtp->pos - 1, SEEK_SET) < 0)
+              fbuf_reset (dtp->u.p.current_unit);
+              if (sseek (dtp->u.p.current_unit->s, dtp->pos - 1,
+                 SEEK_SET) < 0)
                 {
                   generate_error (&dtp->common, LIBERROR_OS, NULL);
                   return;