[patch, libgfortran] Fix for PR 19451

Thomas Koenig Thomas.Koenig@online.de
Wed Jan 19 22:16:00 GMT 2005


*sigh* I'll get this right first time, someday.  Attaching a
"cvs diff -c" this time.

This was bubblestrapped and regtested on i386-unknown-linux-gnu.

I consider this a trivial patch, which I gladly donate to the FSF.

Ok?

	Thomas

2005-01-19  Thomas Koenig  <Thomas.Koenig@online.de>

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

	PR libfortran/19451
	* open_readonly_file.f90:  New test.
-------------- next part --------------
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 22:10:04 -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)
-------------- next part --------------
! { dg do-run }
! PR 19451 : writing to a read-only file with contents
!            would cause a segfault when iostat or err were present
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"
  if (iostat == 0) call abort
  write(10,*,err=20) "Hello, world"
  call abort
20 continue
end


More information about the Fortran mailing list