https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96486
--- Comment #3 from Susi Lehtola <jussilehtola at fedoraproject dot org> ---
program zerolen_value
implicit none
character(len=*), parameter :: name='HOSTNAME'
character(len=:), allocatable :: value
integer :: l, err
call get_environment_variable(name,length=l,status=err)
if (err.ne.0) then
stop 'System variable unassigned'
endif
allocate( character(len=l) :: value, stat=err )
if (err.ne.0) then
stop 'Variable could not be allocated'
endif
! If the environment variable has not been set, l=0, and the
! following get_environment_variable call crashes.
! if (l.gt.0) then
call get_environment_variable(name,value,status=err)
if (err.ne.0) then
stop 'System variable corrupted'
endif
! endif
end program zerolen_value