This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libfortran/19451] Read after a write with a read only file
- From: "Thomas dot Koenig at online dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 Jan 2005 21:35:24 -0000
- Subject: [Bug libfortran/19451] Read after a write with a read only file
- References: <20050114195655.19451.Thomas.Koenig@online.de>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From Thomas dot Koenig at online dot de 2005-01-19 21:35 -------
(In reply to comment #1)
> Confirmed, changing the summary a little more.
>
> Also if the file contained anything, we seg fault when finishing the write
(which seems wrong).
Here's a test case for that:
$ cat open+write2.f90
program main
call system("rm -f asdf.dat; echo foo > asdf.dat; chmod u-w asdf.dat")
open(file="asdf.dat",unit=10,action="read")
write(10,*,iostat=i) "Hello, world"
end
$ gfortran open+write2.f90
$ ./a.out
Segmentation fault
Same thing with iostat= as with err=. Without it, things work:
$ cat open+write3.f90
program main
call system("rm -f asdf.dat; echo foo > asdf.dat; chmod u-w asdf.dat")
open(file="asdf.dat",unit=10,action="read")
write(10,*) "Hello, world"
end
$ gfortran open+write3.f90
$ ./a.out
At line 4 of file open+write3.f90
Fortran runtime error: Cannot write to file opened for READ
... which is correct behaviour.
After some poking around, it seems that finalize_transfer()
insists on doing something even if ioparm.library_return
is not equal to LIBRARY_OK.
I've tried out the following patch:
Index: transfer.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/io/transfer.c,v
retrieving revision 1.26
diff -c -r1.26 transfer.c
*** transfer.c 15 Jan 2005 08:10:19 -0000 1.26
--- transfer.c 19 Jan 2005 21:26:07 -0000
***************
*** 1383,1388 ****
--- 1383,1391 ----
static void
finalize_transfer (void)
{
+ if (ioparm.library_return != LIBRARY_OK)
+ return;
+
if ((ionml != NULL) && (ioparm.namelist_name != NULL))
{
if (ioparm.namelist_read_mode)
which didn't seem to do any harm (no testcase failures) and
which appears to fix the problem, but I don't know wether this
introduces any cleanup issues.
Thomas
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19451