[Bug fortran/96486] get_environment_variable crashes for environment variables that are empty strings

jussilehtola at fedoraproject dot org gcc-bugzilla@gcc.gnu.org
Sat Aug 8 15:49:47 GMT 2020


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

--- Comment #28 from Susi Lehtola <jussilehtola at fedoraproject dot org> ---
Harald, Andreas, thanks for clarifying: yes, "crash" == Fortran runtime error.
The program should run just fine, since the return array has the proper size
given by get_environment_variable. Instead, it ends in a runtime error in
get_environment_variable.

The root cause is that get_environment_variable_i4 in
libgfortran/intrinsics/env.c checks for a zero size return array before it
checks what size an array is needed: when the environment variable is set to an
empty string, a zero-size Fortran array is sufficient. The return value size
check should just be moved a few lines down to where the memcpy() is performed.


More information about the Gcc-bugs mailing list