Silverfrost Forums

Welcome to our forums

Internal WRITE error goes undetected

7 Jul 2019 1:03 #23930

The following program does formatted writes of an integer to an internal file (i.e., a buffer) with three different variations. The second WRITE writes uses a field width of 4, which is adequate for the integer 123, but the resulting string is longer than the record length of the internal file, which is 3.

program asterisks
  character(3) str
  character(100) msg
  n=123
  print *,'Str Iostat Message'
  str='xyz'; msg=' - '; write(str,'(i0)',iostat=i,iomsg=msg) n
  write(*,10) str,i,trim(msg)
  str='xyz'; msg=' - '; write(str,'(i4)',iostat=i,iomsg=msg) n
  write(*,10) str,i,trim(msg)
  str='xyz'; msg=' - '; write(str,'(i2)',iostat=i,iomsg=msg) n
  write(*,10) str,i,trim(msg)
10 format(1x,A3,i5,4x,A)
end

I think that the second WRITE should yield a positive IOSTAT value, a suitable IOMSG, and leave the record unchanged. FTN95 8.51 (32 and 64-bit) returns IOSTAT = 0, instead, and the written record is incorrect.

 Str Iostat Message
 123    0
  12    0
 **     0

For the second case, Intel Fortran gives IOMSG='output statement overflows record, unit -5, file Internal Formatted Write'.

7 Jul 2019 4:54 #23931

I agree this would be a useful additional run-time check. Though it is the programmer's responsibility to check such things.

The NAG and gfortran compilers also detect the error with the (I4) formatting at run-time.

8 Jul 2019 6:28 #23936

Thank you for this. I have made a note that it needs fixing.

8 Jul 2019 9:08 #23938

This has now been fixed for the next release of the DLLs.

The iostat is 67 and the message is 'Character buffer too small'.

Please login to reply.