Closed
Description
The Unicode Windows API internally works with (potentially ill-formed) UTF-16 paths that must be converted to from Rust's UTF-8 strings. The conversion happens here:
rust/library/std/src/sys/windows/mod.rs
Lines 159 to 166 in b04c532
encode_wide
does the translation from WTF-8 to UTF-16, leaving a Vec<u16>
with len == cap
. The following calling to push
will then allocate to reserve additional memory for the null-terminating character.
This could be resolved in two ways:
- Call
Vec::with_capacity(EncodeWide::size_hint + 1)
beforehand and then callVec::extend
on EncodeWide. - Make a wrapper around
EncodeWide
that increasesiter::size_hint
by one. Incorporating the final null byte intoiter::next
would add a performance penalty, therefore it would probably be desirable to just adjust the size_hint by one and adding the null-terminator manually.