Bug 18632 – enable use of fromStringz with char[n]

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-03-19T21:45:10Z
Last change time
2021-07-16T08:35:21Z
Keywords
pull
Assigned to
No Owner
Creator
elpenguino+D

Comments

Comment #0 by elpenguino+D — 2018-03-19T21:45:10Z
i.e. ``` char[40] cString; auto someString = cString.fromStringz(); assert((someString.length >= 0) && (someString.length <= 40)); ``` This would behave more like strnlen than strlen, and would be particularly useful when the maximum size of the string is known ahead of time. This would possibly also have the benefit of being @safe and pure.
Comment #1 by issues.dlang — 2018-03-19T22:07:23Z
(In reply to elpenguino+D from comment #0) > This would possibly also have the benefit of being @safe and pure. Without -dip1000, treating the result as @safe would be a huge mistake, because slicing a static array like this is inherently unsafe. The fact that the compiler does not treat slicing static arrays as @system without -dip1000 and scope is a bug (and it's in bugzilla somewhere, but I don't feel like searching for it at the moment). And on that note, the function would have to accept the static array by ref, or it would have a huge @safety bug.
Comment #2 by dlang-bot — 2021-07-11T23:34:27Z
@dkorpel created dlang/phobos pull request #8164 "Fix issue 18632 - enable use of fromStringz with char[n]" fixing this issue: - Fix issue 18632 - enable use of fromStringz with char[n] https://github.com/dlang/phobos/pull/8164
Comment #3 by dlang-bot — 2021-07-16T08:35:21Z
dlang/phobos pull request #8164 "Fix issue 18632 - enable use of fromStringz with char[n]" was merged into master: - 66698dc5f5daed7121cf3715f4be565208478d19 by dkorpel: Fix issue 18632 - enable use of fromStringz with char[n] https://github.com/dlang/phobos/pull/8164