mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 22:21:09 +03:00
Merge pull request #5049 from Burgos/fix-17102
fix issue 17102 - Don't pass null to strlen in std.file.cenforce merged-on-behalf-of: Jack Stouffer <jack@jackstouffer.com>
This commit is contained in:
commit
c6d33505dc
1 changed files with 13 additions and 2 deletions
15
std/file.d
15
std/file.d
|
@ -180,7 +180,7 @@ private T cenforce(T)(T condition, const(char)[] name, const(FSChar)* namez,
|
|||
import core.stdc.wchar_ : wcslen;
|
||||
import std.conv : to;
|
||||
|
||||
auto len = wcslen(namez);
|
||||
auto len = namez ? wcslen(namez) : 0;
|
||||
name = to!string(namez[0 .. len]);
|
||||
}
|
||||
throw new FileException(name, .GetLastError(), file, line);
|
||||
|
@ -197,12 +197,23 @@ private T cenforce(T)(T condition, const(char)[] name, const(FSChar)* namez,
|
|||
{
|
||||
import core.stdc.string : strlen;
|
||||
|
||||
auto len = strlen(namez);
|
||||
auto len = namez ? strlen(namez) : 0;
|
||||
name = namez[0 .. len].idup;
|
||||
}
|
||||
throw new FileException(name, .errno, file, line);
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
// issue 17102
|
||||
try
|
||||
{
|
||||
cenforce(false, null, null,
|
||||
__FILE__, __LINE__);
|
||||
}
|
||||
catch (FileException) {}
|
||||
}
|
||||
|
||||
/* **********************************
|
||||
* Basic File operations.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue