[Issue 15136] If we want toStringz to be fully correct, it needs to stop checking for '\0'
https://issues.dlang.org/show_bug.cgi?id=15136 Dlang Bot changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #6 from Dlang Bot --- dlang/phobos pull request #7806 "fix issue 15136 - If we want toStringz to be fully correct, it needs …" was merged into master: - c55ce44705ddac208d5d7340b60ad2f8eacd0552 by aG0aep6G: fix issue 15136 - If we want toStringz to be fully correct, it needs to stop checking for '\0' https://github.com/dlang/phobos/pull/7806 --
[Issue 15136] If we want toStringz to be fully correct, it needs to stop checking for '\0'
https://issues.dlang.org/show_bug.cgi?id=15136 Dlang Bot changed: What|Removed |Added Keywords||pull --- Comment #5 from Dlang Bot --- @aG0aep6G created dlang/phobos pull request #7806 "fix issue 15136 - If we want toStringz to be fully correct, it needs …" fixing this issue: - fix issue 15136 - If we want toStringz to be fully correct, it needs to stop checking for '\0' https://github.com/dlang/phobos/pull/7806 --
[Issue 15136] If we want toStringz to be fully correct, it needs to stop checking for '\0'
https://issues.dlang.org/show_bug.cgi?id=15136 --- Comment #4 from Steven Schveighoffer--- (In reply to Steven Schveighoffer from comment #3) > assert(s[5] == 'b'); That should have read str[5], obviously :) --
[Issue 15136] If we want toStringz to be fully correct, it needs to stop checking for '\0'
https://issues.dlang.org/show_bug.cgi?id=15136 Steven Schveighofferchanged: What|Removed |Added CC||schvei...@yahoo.com --- Comment #3 from Steven Schveighoffer --- (In reply to John Colvin from comment #2) > It seem to me like this could happen with static arrays directly on the > stack as well, depending on what variables the compiler happens to put > directly after. It can be done with heap-allocated arrays as well: auto s = "hello".idup; auto str = s.toStringz; assert(s.ptr == str); s ~= 'b'; assert(s[5] == 'b'); The assumption that a coincidental null character after the string must mean it is part of a literal is completely unsound. Not to mention, if the null happens to be on a 4-byte boundary, then it doesn't even look at it, potentially wasting an allocation. What we really need, as Jonathan says, is a way to tell if a string pointer points at a string literal or not. This should be possible I would think, as the linker puts all the literals into the same section, no? All we have to do is check whether the array points in that section, and the null character pointer is in that section, and the null character is null. Otherwise, allocate. --
[Issue 15136] If we want toStringz to be fully correct, it needs to stop checking for '\0'
https://issues.dlang.org/show_bug.cgi?id=15136 Shriramana Sharmachanged: What|Removed |Added CC||samj...@gmail.com --
[Issue 15136] If we want toStringz to be fully correct, it needs to stop checking for '\0'
https://issues.dlang.org/show_bug.cgi?id=15136 John Colvinchanged: What|Removed |Added CC||john.loughran.colvin@gmail. ||com --- Comment #2 from John Colvin --- It seem to me like this could happen with static arrays directly on the stack as well, depending on what variables the compiler happens to put directly after. --
[Issue 15136] If we want toStringz to be fully correct, it needs to stop checking for '\0'
https://issues.dlang.org/show_bug.cgi?id=15136 Andrej Mitrovicchanged: What|Removed |Added CC||andrej.mitrov...@gmail.com --- Comment #1 from Andrej Mitrovic --- +1. If we really need to avoid memory allocations let's just add an overload or something like assumeZeroTerminated or something.. --