Bug 19133 – core.exception.rangeerror@std/file.d(3812):

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Solaris
Creation time
2018-08-01T21:37:05Z
Last change time
2019-04-06T16:42:46Z
Assigned to
Eduard Staniloiu
Creator
crayolist

Comments

Comment #0 by crayolist — 2018-08-01T21:37:05Z
On Solaris dirent is defined druntime/src/core/sys/posix/dirent.d like this; else version (Solaris) { struct dirent { ino_t d_ino; off_t d_off; ushort d_reclen; char[1] d_name; } This commit; Commit: 5e88b67808022adba692451791422cb9fd58b490 [5e88b67] Parents: 0ff1cfe045 Author: Alexandru Jercaianu <[email protected]> Date: Thursday, October 5, 2017 1:20:39 PM Committer: Alexandru Jercaianu minor code refactoring introduced a regression with the following change; - private this(string path, core.sys.posix.dirent.dirent* fd) @safe + private this(string path, core.sys.posix.dirent.dirent* fd) @trusted { import std.path : buildPath; - static auto trustedStrlen(const char* str) @trusted - { - return core.stdc.string.strlen(str); - } - - immutable len = trustedStrlen(&fd.d_name[0]); + fd.d_name[$ - 1] = 0; + immutable len = strlen(&fd.d_name[0]); _name = buildPath(path, fd.d_name[0 .. len]); Specifically the line fd.d_name[$ - 1] = 0; is equivalent to fd.d_name[0] = 0, thus len is always 0.
Comment #1 by edi33416 — 2018-12-12T11:11:18Z
By the looks of it, this PR https://github.com/dlang/phobos/pull/5838 also solves this issue. Closing *** This issue has been marked as a duplicate of issue 17962 ***
Comment #2 by crayolist — 2018-12-12T17:03:52Z
This issue is not resolved. Let me try to clarify the issue again; This line; https://github.com/dlang/phobos/blob/d262d06a14ca3e6fb659859999931f15c8e01b7c/std/file.d#L3864 will not correctly compute 'len' in the case of Solaris because 'dirent' is defined like this; https://github.com/dlang/druntime/blob/75eb3c6e307fbd2488452d0e100724e49c31f35d/src/core/sys/posix/dirent.d#L255 Notice that 'dirent.d_name' is a one character buffer. The line; immutable len = fd.d_name[].representation.countUntil(0); cannot compute the correct length because the range has 1 element.
Comment #3 by edi33416 — 2018-12-14T13:35:19Z
You are right. Apologies for closing this eagerly. I've assigned it to me.
Comment #4 by edi33416 — 2018-12-14T14:24:39Z
Comment #5 by github-bugzilla — 2018-12-24T19:21:57Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/cb1dd9fef69f25210d7fb43cb130fb3ab158776f Fix Issue 19133 - core.exception.rangeerror@std/file.d(3812) https://github.com/dlang/phobos/commit/e7cfc5c1f2bce8f79bcf74f8daa26772afd052a2 Merge pull request #6805 from edi33416/issue_19133 Fix Issue 19133 - core.exception.rangeerror@std/file.d(3812)
Comment #6 by dlang-bot — 2019-04-06T16:42:46Z
dlang/phobos pull request #6947 "[dmd-cxx] Backport Solaris and DragonflyBSD ports" was merged into dmd-cxx: - 8a832d917ffe1bdc30acb249fd7ad5b61b1470e0 by Eduard Staniloiu: Fix Issue 19133 - core.exception.rangeerror@std/file.d(3812) https://github.com/dlang/phobos/pull/6947