https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61632

            Bug ID: 61632
           Summary: memory corruption in Fortran RTL when writing
                    formatted data
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arnaud02 at users dot sourceforge.net

Problem 1: using the following program:
      program p
      call ss()
      call ss()
      end program p
      subroutine ss
      CHARACTER(3), save :: ZTYP(3)
      DATA ZTYP /'XXX','YYY','ZZZ'/
      write(*,600,IOSTAT=iosa) 0.0,ZTYP
      write(*,*) 'iostat=',iosa
 600  FORMAT(1PE13.5,4X,A3)
      end subroutine ss

with gfortran 4.9.0 results in a executable that crashes:
  0.00000E+00    XXX
 iostat=        5006
  0.00000E+00    XXX

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

A run under valgrind shows:
  0.00000E+00    XXX
 iostat=        5006
  0.00000E+00    XXX
==13768== Invalid read of size 8
==13768==    at 0x414250: _gfortrani_format_error (format.c:1147)
==13768==    by 0x4047D6: require_type.part.7 (transfer.c:1158)
==13768==    by 0x406718: formatted_transfer (transfer.c:1150)
==13768==    by 0x404AE5: _gfortran_transfer_array (transfer.c:2170)

gfortran 4.7.1 is not affected but gfortran 4.8.2 and 4.9.0 are.


Problem 2: using the following program:
      program p
      call ss()
      call ss()
      end program p
      subroutine ss
      CHARACTER(3), save :: ZTYP(3)
      DATA ZTYP /'XXX','YYY','ZZZ'/
      write(*,600) 0.0,ZTYP
 600  FORMAT(1PE13.5,A3)
      end subroutine ss

with gfortran 4.9.0 results in a executable that produces:
--
  0.00000E+00XXX
At line 8 of file io2.f (unit = 6, file = 'stdout')
Fortran runtime error: Expected REAL for item 3 in formatted transfer, got
CHARACTER
(1PE13.5,A3)
   ^
--
The message is unclear as there are only 2 items. Moreover the expected type
looks incorrect. gfortran 4.6.3, 4.7.2, 4.8.2 and 4.9.0 are affected.

Reply via email to