Open jrvanwhy opened 3 years ago
Actually, looking again, encode_utf8
takes a &mut [u8]
, so it requires its input to be initialized. Therefore I believe solutions 2 and 3 from my post are unsound.
An additional option to avoid unnecessary overhead is to implement our own char-to-utf8 logic.
Actually, grepping through the source shows that uninitialized
is used in several more places, which complicates the fix.
uWrite::write_char
contains an unsound use ofcore::mem::uninitialized
(see the docs forstd::mem::MaybeUninit
):The usual fix is to use
std::mem::MaybeUninit
, but this crate has a minimum supported Rust version of 1.34, which predates the stabilization ofstd::mem::MaybeUninit
in 1.36.There are a few possible fixes:
std::mem::MaybeUninit
.std::mem::MaybeUninit
in this crate (i.e. use a union to make it sound), which involves significantly more unsafe code.