[Issue 18279] New: rt.util.utf does not properly reserve buffer in toUTF16/toUTF16z
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jan 22 17:46:24 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18279
Issue ID: 18279
Summary: rt.util.utf does not properly reserve buffer in
toUTF16/toUTF16z
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: trivial
Priority: P1
Component: druntime
Assignee: nobody at puremagic.com
Reporter: n8sh.secondary at hotmail.com
The offending pattern:
```
wchar[] r;
size_t slen = s.length;
r.length = slen;
r.length = 0;
// ... followed by code that appends to r with ~=
```
The apparent intention is to preallocate the buffer but this idiom doesn't work
as pointed out by Dmitry Olshansky: "On append the slice is not the tail so it
will reallocate."
https://github.com/dlang/phobos/pull/6024#discussion_r160918451
--
More information about the Digitalmars-d-bugs
mailing list