Quantcast
Channel: Fortran
Viewing all articles
Browse latest Browse all 3108

Small program segfaults on READ from internal file

$
0
0

The following program gives a segfault with Intel 15.0.2 on Linux:

PROGRAM read_empty_substing
  CHARACTER(LEN=20) :: c_in = "hello"
  CHARACTER(LEN=20) :: c_out
  INTEGER :: i_iostat

  ! These statements give a segfault with Intel 15.0.2
  READ(c_in(2:1), '(A)')  c_out
  READ(c_in(2:1), '(A)', IOSTAT=i_iostat)  c_out

  ! The following statements give end-of-file as expected:
  !READ(c_in(2:1), *) c_out
  !READ(c_in(2:1), *, IOSTAT=i_iostat) c_out

  print *, TRIM(c_out)
END PROGRAM

As you can see, we try to read from an empty substring of c_in, and I do expect an error condition, i.e. i_iostat/=0. Instead I get a segfault. The read statements with format string segfaults, while the list directed read gives end-of-file. Am I supposed to check the length of the internal file before I read from it, or could this be a compiler bug?

Øyvind

------------------------

(gdb) run
Starting program: /fs/auto/home/oyvindj/tmp/read_segfault/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Catchpoint -2 (signal SIGSEGV), 0x00000000004804c6 in __intel_ssse3_rep_memcpy ()
(gdb) bt
#0  0x00000000004804c6 in __intel_ssse3_rep_memcpy ()
#1  0x0000000000409546 in for_read_int_fmt_xmit ()
#2  0x000000000040783f in for_read_int_fmt ()
#3  0x0000000000402e01 in read_empty_substing () at read.f90:7
#4  0x0000000000402d5e in main ()

 


Viewing all articles
Browse latest Browse all 3108

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>