mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 05:30:33 +03:00
Fix bugzilla issue 24549 -- environment.get(null) segfaults on Linux
This commit is contained in:
parent
fcccc61b95
commit
82e8e32b2f
1 changed files with 15 additions and 0 deletions
|
@ -350,6 +350,8 @@ static:
|
|||
*/
|
||||
bool opBinaryRight(string op : "in")(scope const(char)[] name) @trusted
|
||||
{
|
||||
if (name is null)
|
||||
return false;
|
||||
version (Posix)
|
||||
return core.sys.posix.stdlib.getenv(name.tempCString()) !is null;
|
||||
else version (Windows)
|
||||
|
@ -451,6 +453,10 @@ private:
|
|||
// doesn't exist.
|
||||
void getImpl(scope const(char)[] name, scope void delegate(const(OSChar)[]) @safe sink) @trusted
|
||||
{
|
||||
// fix issue https://issues.dlang.org/show_bug.cgi?id=24549
|
||||
if (name is null)
|
||||
return sink(null);
|
||||
|
||||
version (Windows)
|
||||
{
|
||||
// first we ask windows how long the environment variable is,
|
||||
|
@ -600,6 +606,15 @@ private:
|
|||
assert("std_process" !in environment);
|
||||
}
|
||||
|
||||
// https://issues.dlang.org/show_bug.cgi?id=24549
|
||||
@safe unittest
|
||||
{
|
||||
import std.exception : assertThrown;
|
||||
assert(environment.get(null) is null);
|
||||
assertThrown(environment[null]);
|
||||
assert(!(null in environment));
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Functions and classes for process management.
|
||||
// =============================================================================
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue