On Sunday, 15 August 2021 at 08:11:39 UTC, rempas wrote:
On Sunday, 15 August 2021 at 07:43:59 UTC, jfondren wrote:
```d
unittest {
    char* s = "John".dup.ptr;
    s[0] = 'X'; // no segfaults
    assert(s[0..4] == "Xohn"); // ok
}
```


Well, that one didn't worked out really well for me. Using `.dup.ptr`, didn't added a null terminated character

dup() isn't aware of the NUL since that's outside the slice of the string. It only copies the chars in "John". You can use toStringz to ensure NUL termination:
https://dlang.org/phobos/std_string.html#.toStringz

Reply via email to