rust-lexical icon indicating copy to clipboard operation
rust-lexical copied to clipboard

[BUG] Safety comments for MaybeUninit::assume_init calls are wrong, calls are UB

Open saethlin opened this issue 2 years ago • 0 comments

This code executes UB: https://github.com/Alexhuszagh/rust-lexical/blob/09c686b075096d48155cfb32265068f962afc56c/lexical-write-float/src/radix.rs#L70-L72

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.

saethlin avatar May 24 '23 03:05 saethlin