Undefined behavior in `fmt::Debug` impl for `os::windows::Library`
Cldfire opened this issue · comments
Jarek Samic commented
I happened to notice this while glancing around the code for #82. Link to src.
let mut buf =
mem::MaybeUninit::<[mem::MaybeUninit::<WCHAR>; 1024]>::uninit().assume_init();
Based on the docs for assume_init
, it sounds like this is UB:
Calling this when the content is not yet fully initialized causes immediate undefined behavior.
Jarek Samic commented
Oh, duh. That's not UB because the contents of the array are actually initialized there, as uninitialized data.
Also realized it's copied from the impl in the stdlib.
Closing, my bad! 😄
Simonas Kazlauskas commented
The assume_init
is fine becaue the array values are themselves MaybeUninit
, yeah.