c Summary: Direct unformatted read beyond EOF cores c This program demonstrates a bug in gfortran/libgfortran. c The bug is that a c program dumps core when reading beyond the end of c a access='direct', form='unformatted' file instead c of transfering control to 'err=' label. c Also, returns incorrectly when reading at end of file.
c To test c dd if=/dev/zero of=shortfile bs=11811 count=1 c ./a.out c Bus error (core dumped) c dd if=/dev/zero of=shortfile bs=11812 count=1 c ./a.out c should not get here c before 779 inbuf(1)= 32 c STOP 0 c Note: in the above case, the value of inbuf(1) got set to a space c When compiled with ifort or g77, the correct output is produced c in both cases. c ./a.out c at 779, all is good c Problem occurs in c GNU Fortran 95 (GCC 4.0.1) c GNU Fortran 95 (GCC 4.0.2 20050804 (prerelease)) c GNU Fortran 95 (GCC 4.1.0 20050806 (experimental)) c gfortran -v c Using built-in specs. c Target: i686-pc-linux-gnu c Configured with: ../../NetSrc/gcc-4.1-20050806/configure --prefix=/home/bswift/afrl/ builddev/NetInst/gcc-4.1-20050806 --enable-languages=c,f95 --with-gmp=/home/bswift/afrl/ builddev/NetInst/gmp-4.1.4 --with-mpfr=/home/bswift/afrl/builddev/NetInst/mpfr-2.1.2 c Thread model: posix c gcc version 4.1.0 20050806 (experimental) implicit none integer nbytes integer inbuflen parameter (inbuflen=32768) integer*1 inbuf(inbuflen) integer k inbuf(1)=5 nbytes=11812 open(35,file='shortfile',access='direct',recl=nbytes,form $ ='unformatted') read(35,rec=2,err=779) (inbuf(k),k=1,nbytes) write(*,*) 'should not get here' write(*,*) 'before 779 inbuf(1)=',inbuf(1) stop 779 write(*,*) 'at 779, all is good' end -- Summary: Direct unformatted read beyond EOF cores Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: libfortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bsp at kithrup dot com CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23321