-
Notifications
You must be signed in to change notification settings - Fork 40
Closed
Labels
Milestone
Description
This code executes UB:
rust-lexical/lexical-write-float/src/radix.rs
Lines 70 to 72 in 09c686b
| let buffer: mem::MaybeUninit<[u8; SIZE]> = mem::MaybeUninit::uninit(); | |
| // SAFETY: safe, since we never read bytes that weren't written. | |
| let mut buffer = unsafe { buffer.assume_init() }; |
The docs for MaybeUninit::uninit do not have an exception for this use case. This code is UB, because the MaybeUninit is not initialized.
The safety comment is also technically wrong; the value is read by the assignment and return from MaybeUninit::assume_init.
This problem is reliably reported by running cargo +nightly miri test --all-features.
The existing MaybeUninit APIs are not exactly elegant, but I think they can be slotted in pretty neatly with the existing abstractions you have here. I can take a shot at fixing this in the coming days/weeks.
Alexhuszagh