This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Possible bug in g77's 'backspace'.


I believe there is a bug in the way g77 implements the "backspace"
statement for sequential binary files. (Actually, it might be a
problem with libf2c, as I see it also with f2c). I am running the
version of g77 that comes with egcs-1.1 (more details below).

A short program to expose the bug follows. The scheme "read a record,
backspace if there is an error and try again" is useful sometimes when
some piece of information might or might not be present in the
file. In this case, I first attempt to read three integers from the
record. As there are only two, an error condition is set (iostat=110
[off end of record]) and control is transferred to a block where I
"backspace" the file and attempt to read the record again. But then I
get garbage. It looks as if, after the error condition, the
"backspace" is failing to position the file correctly.

I see the same behavior with f2c and with The Portland Group's pgf77
and pgf90. 

NAG's f90 on Linux gives correct results, and tests on a DEC Alpha
(using DEC Fortran f77 and f90) and on a SGI machine (f77 and f90)
work as expected.

c
      program backspace_bug
      implicit none
c
      integer status
      integer n1, n2, dummy
      
      open(1,file='BIN',status='unknown',form='unformatted')
      n1 = 2
      n2 = 3
      write(1) n1, n2
      close(1)

      n1 = -1
      n2 = -1
      dummy = -100
      open(1,file='BIN',status='old',form='unformatted')
      read (1,err=900,iostat=status) n1, n2, dummy
      goto 1000
 900  continue
         write(6,*) 'Read error (record too short). Iostat: ', status
         write(6,*) 'Values read: ', n1, n2, dummy
         write(6,*) 'Will try again after backspacing'
         backspace(1)
         read (1) n1, n2
 1000 continue
      write(6,*) n1, n2
      end

$ g77 -o back back.f
$ back
 Read error (record too short). Iostat:  110
 Values read:  2 3 -100
 Will try again after backspacing
 50331648 134217728
$

Here is the output of 'g77 --verbose':

g77 version egcs-2.91.57 19980901 (egcs-1.1 release) 
(from FSF-g77 version 0.5.24-19980804)
Driving: g77 -v -c -xf77-version /dev/null -xnone
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/specs
gcc version egcs-2.91.57 19980901 (egcs-1.1 release)
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/cpp 
 -lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=91 -D__ELF__ 
 -D__unix__ -D__linux__ -D__unix -D__linux -Asystem(posix) 
 -D_LANGUAGE_FORTRAN -traditional -Asystem(unix) -Acpu(i386) 
 -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di686 -Dpentiumpro 
 -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__ /dev/null /dev/null
GNU CPP version egcs-2.91.57 19980901 (egcs-1.1 release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/local/i686-pc-linux-gnu/include
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/include
 /usr/include
End of search list.
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/f771 
 -fnull-version -quiet -dumpbase g77-version.f -version -fversion 
 -o /home/wdpgaara/scratch/ccT7YVFL.s /dev/null
GNU F77 version egcs-2.91.57 19980901 (egcs-1.1 release) 
(i686-pc-linux-gnu) compiled by GNU C version egcs-2.90.23 980102 
(egcs-1.0.1 release).
GNU Fortran Front End version 0.5.24-19980804
 as -V -Qy -o /home/wdpgaara/scratch/cczX50VO.o 
 /home/wdpgaara/scratch/ccT7YVFL.s
GNU assembler version 2.9.1 (i686-pc-linux-gnu), using BFD version 2.9.1.0.4
 ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 
 -o /home/wdpgaara/scratch/ccvhe11e /home/wdpgaara/scratch/cczX50VO.o 
 /usr/lib/crt1.o /usr/lib/crti.o 
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/crtbegin.o 
 -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57 
 -L/usr/local/i686-pc-linux-gnu/lib -L/usr/local/lib -lg2c -lm -lgcc 
 -lc -lgcc
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/crtend.o 
 /usr/lib/crtn.o
 /home/wdpgaara/scratch/ccvhe11e
__G77_LIBF77_VERSION__: 0.5.23
@(#)LIBF77 VERSION 19970919
__G77_LIBI77_VERSION__: 0.5.23
@(#) LIBI77 VERSION pjw,dmg-mods 19980617
__G77_LIBU77_VERSION__: 0.5.23
@(#) LIBU77 VERSION 19980709


Alberto Garcia  Dept. Fisica Aplicada II, UPV, Apdo. 644, 48080 Bilbao, SPAIN
Tel: +34-944.647.700 ext 2495; Fax: +34-944.648.500 Email: wdpgaara@lg.ehu.es






Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]