nagisa / rust_libloading

Bindings around the platform's dynamic library loading primitives with greatly improved memory safety.

Home Page:https://docs.rs/libloading

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Undefined behavior in `fmt::Debug` impl for `os::windows::Library`

Cldfire opened this issue · comments

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.

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! 😄

The assume_init is fine becaue the array values are themselves MaybeUninit, yeah.