From 0e69bba9fc926fd529f51aa9e7f585c27b88c1e3 Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Sun, 23 Jan 2005 02:18:33 +0000 Subject: [PATCH] re PR libfortran/19451 (Read after a write with a read only file) 2005-01-22 Thomas Koenig 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 | 5 +++++ gcc/testsuite/gfortran.dg/open_readonly_1.f90 | 14 ++++++++++++++ libgfortran/ChangeLog | 6 ++++++ libgfortran/io/transfer.c | 3 +++ 4 files changed, 28 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/open_readonly_1.f90 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b39fb693f0c7..f63c8dba2060 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-01-22 Thomas Koenig + + PR libfortran/19451 + * open_readonly_1.f90: New test. + 2005-01-22 Thomas Koenig 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 index 000000000000..622a07d2aeea --- /dev/null +++ b/gcc/testsuite/gfortran.dg/open_readonly_1.f90 @@ -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 + diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index c2218fba7179..1296ab2a2475 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,9 @@ +2005-01-22 Thomas Koenig + + PR libfortran/19451 + * io/transfer.c (finalize_transfer): Don't do anything if + there is an error condition. + 2005-01-22 David Edelsohn PR libgfortran/19052 diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c index 114ed92abb95..1dcbc7ff74c8 100644 --- a/libgfortran/io/transfer.c +++ b/libgfortran/io/transfer.c @@ -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) -- 2.43.5