re PR libfortran/19451 (Read after a write with a read only file)
authorThomas Koenig <Thomas.Koenig@online.de>
Sun, 23 Jan 2005 02:18:33 +0000 (02:18 +0000)
committerPaul Brook <pbrook@gcc.gnu.org>
Sun, 23 Jan 2005 02:18:33 +0000 (02:18 +0000)
2005-01-22  Thomas Koenig  <Thomas.Koenig@online.de>

PR libfortran/19451
* io/transfer.c (finalize_transfer):  Don't do anything if
there is an error condition.
* open_readonly_1.f90:  New test.

From-SVN: r94101

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

index b39fb693f0c71c584c508b18c3ffa1c6c5d6e425..f63c8dba206014efd868c4e4b08d916de1e0bec5 100644 (file)
@@ -1,3 +1,8 @@
+2005-01-22  Thomas Koenig  <Thomas.Koenig@online.de>
+
+       PR libfortran/19451
+       * open_readonly_1.f90:  New test.
+
 2005-01-22  Thomas Koenig  <Thomas.Koenig@online.de>
 
        PR libfortran/18982
diff --git a/gcc/testsuite/gfortran.dg/open_readonly_1.f90 b/gcc/testsuite/gfortran.dg/open_readonly_1.f90
new file mode 100644 (file)
index 0000000..622a07d
--- /dev/null
@@ -0,0 +1,14 @@
+! { dg-do run }
+! PR19451
+! Writing to a non-empty readonly file caused a segfault.
+! We were still trying to write the EOR after an error ocurred
+program prog
+  open (unit=10, file='PR19451.dat')
+  write (10,*) "Hello World"
+  close (10)
+  open (unit=10, file='PR19451.dat', action="read")
+  write (10,*,err=20) "Hello World"
+  call abort()
+  20 continue
+end program
+
index c2218fba7179f20167d8321404635d8c89a318fd..1296ab2a2475e61b7bd2232b8868cb2cc15e3f6c 100644 (file)
@@ -1,3 +1,9 @@
+2005-01-22  Thomas Koenig  <Thomas.Koenig@online.de>
+
+       PR libfortran/19451
+       * io/transfer.c (finalize_transfer):  Don't do anything if
+       there is an error condition.
+
 2005-01-22  David Edelsohn  <edelsohn@gnu.org>
 
        PR libgfortran/19052
index 114ed92abb951b2d28208aff727e99a884e00112..1dcbc7ff74c8941c3a1c634605ac2721c2a08588 100644 (file)
@@ -1389,6 +1389,9 @@ next_record (int done)
 static void
 finalize_transfer (void)
 {
+  if (ioparm.library_return != LIBRARY_OK)
+    return;
+
   if ((ionml != NULL) && (ioparm.namelist_name != NULL))
     {
        if (ioparm.namelist_read_mode)