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

            Bug ID: 77505
           Summary: Negative character length not treated as LEN=0
           Product: gcc
           Version: 5.4.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: urbanjost at comcast dot net
  Target Milestone: ---

From section 4.4.5.2-5 of the f2008 standard, I think negative character
lengths
should be treated as LEN=0. In the following sample, if I enter a negative
value
the code gets a segmentation fault using gfortran 5.4.0 on Cygwin, at least.

program rabbithole
! 4.4.5.2-5 If the character length parameter value evaluates to a negative
value, the length of character entities declared is zero. 
implicit none
character(len=:),allocatable    :: text_block(:)
integer                         :: i
integer                         :: ii
character(len=10)               :: cten='abcdefghij'
character(len=20)               :: ctwenty='abcdefghijabcdefghij'
   write(*,*)'DOES A NEGATIVE VALUE ACT LIKE LEN=0? (4.4.5.2-5)'
   write(*,*)'ENTER NEGATIVE LENGTH '  ! enter a negative number to be mean
   read(*,*)ii
   text_block=[ character(len=ii) :: cten, ctwenty ] 
   write(*,*)'WRITE IT'
   write(*,'(a)')(trim(text_block(i)),i=1,size(text_block))
end program rabbithole

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

Backtrace for this error:
#0  0xFFFFFFFFFFFFFFFF
#1  0xFFFFFFFFFFFFFFFF
#2  0xFFFFFFFFFFFFFFFF
#3  0xFFFFFFFFFFFFFFFF
#4  0xFFFFFFFFFFFFFFFF
#5  0xFFFFFFFFFFFFFFFF
#6  0xFFFFFFFFFFFFFFFF
#7  0xFFFFFFFFFFFFFFFF
#8  0xFFFFFFFFFFFFFFFF
#9  0xFFFFFFFFFFFFFFFF
#10  0xFFFFFFFFFFFFFFFF
#11  0xFFFFFFFFFFFFFFFF
#12  0xFFFFFFFFFFFFFFFF
#13  0xFFFFFFFFFFFFFFFF
/home/urbanjs/.twm/scripts_daily/quiet: line 8: 23784 Segmentation fault     
(core dumped) $COMMAND

CYGWIN_NT-10.0 buzz 2.6.0(0.304/5/3) 2016-08-31 14:32 x86_64 Cygwin

GNU Fortran (GCC) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.

Reply via email to