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]
Other format: [Raw text]

[Bug libfortran/24700] New: Bad write after backing up from end of file


The following program from http://gcc.gnu.org/ml/fortran/2005-11/msg00084.html
incorrectly writesthe 'TEST' file.  Thanks to Georgy Salnikov for finding and
submitting this bug.  

      PROGRAM TEST
      CHARACTER*8 TXT
      DATA TXT/'**TEST**'/
      OPEN (1, FILE='TEST', STATUS='UNKNOWN', FORM='UNFORMATTED')
      WRITE (1) TXT
      REWIND 1
      READ (1, END=1) TXT
      READ (1, END=1) TXT
 1    CONTINUE
      BACKSPACE 1
      WRITE (1) TXT
      CLOSE (1, STATUS='KEEP')
      END

Georgy also submitted a patch which is considered obvious:

diff -Naur gcc-4.0.2.orig/libgfortran/io/transfer.c
gcc-4.0.2/libgfortran/io/transfer.c
--- gcc-4.0.2.orig/libgfortran/io/transfer.c    2005-09-12 01:55:16.000000000
+0700
+++ gcc-4.0.2/libgfortran/io/transfer.c 2005-10-15 12:29:13.000000000 +0700
@@ -1641,11 +1641,13 @@
          {
            generate_error (ERROR_END, NULL);
            current_unit->endfile = AFTER_ENDFILE;
+           current_unit->current_record = 0;
          }
        break;

       case AFTER_ENDFILE:
        generate_error (ERROR_ENDFILE, NULL);
+       current_unit->current_record = 0;
        break;
       }
 }

Test results to follow:


-- 
           Summary: Bad write after backing up from end of file
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
        AssignedTo: jvdelisle at gcc dot gnu dot org
        ReportedBy: jvdelisle at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24700


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