Runtime error occurs when the type of the value argument is
character(0): "Zero-length string passed as value...".
The status argument, intent(out), will contain -1 if the value
of the environment is too large to fit in the value argument, this
is the case if the type is character(0) so there is no reason to
produce a runtime error if the value argument is zero length.
2020-08-24 Mark Eggleston <markeggleston@gcc.gnu.org>
libgfortran/
PR fortran/96486
* intrinsics/env.c: If value_len is > 0 blank the string.
Copy the result only if its length is > 0.
2020-08-24 Mark Eggleston <markeggleston@gcc.gnu.org>
gcc/testsuite/
PR fortran/96486
* gfortran.dg/pr96486.f90: New test.
--- /dev/null
+! { dg-do run }
+
+program test
+ implicit none
+ character(0) :: value
+ integer :: l, stat
+ call get_environment_variable("HOME",value,length=l,status=stat)
+ if (stat.ne.-1) stop 1
+end program test
if (value != NULL)
{
- if (value_len < 1)
- runtime_error ("Zero-length string passed as value to "
- "get_environment_variable.");
- else
+ if (value_len > 0)
memset (value, ' ', value_len); /* Blank the string. */
}
memcpy (value, res, value_len);
stat = GFC_VALUE_TOO_SHORT;
}
- else
+ else if (res_len > 0)
memcpy (value, res, res_len);
}
}