-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use mem::MaybeUninit instead of mem::uninitialized() since Rust 1.36 #101
Conversation
8dc1fd6
to
fe47137
Compare
fe47137
to
53ed376
Compare
6bd5ee6
to
f9d38fb
Compare
… undefined behavior
f9d38fb
to
8edc047
Compare
I have addressed the review comment at 8edc047. Instead of (I apologize many force pushes. I don't have Windows machine so I needed to check Appveyor result instead) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks but I believe this is still unsafe. See: file:///home/steb/.local/lib/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/share/doc/rust/html/std/mem/union.MaybeUninit.html#examples-1
src/win.rs
Outdated
} | ||
#[rustversion::since(1.36)] | ||
unsafe fn get_console_screen_buffer_info(handle: HANDLE) -> io::Result<CONSOLE_SCREEN_BUFFER_INFO> { | ||
let mut buffer_info = ::std::mem::MaybeUninit::uninit().assume_init(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to call assume_init
after filling the buffer. That is, it should call GetConsoleScreenBufferInfo(handle, buffer_info.as_mut_ptr()
then buffer_info.assume_init()
(if there was no error).
We can't take a reference to uninitialized memory (which is why this type was introduced).
Ahh, ok, I misunderstood the semantics of |
4fc3a93
to
069fd74
Compare
069fd74
to
65801a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM.
And yeah, uninitialized values are tricky business...
Thank you for correcting me and helping to understand correctly. |
I noticed that CI fails since this crate is using deprecated
std::mem::uninitialized()
.https://ci.appveyor.com/project/Stebalien/term/builds/26853323/job/880r4cnu5lhfaccv
This PR uses
MaybeUninit
which replacesstd::mem::uninitialized()
using a compiler version switch provided byrustversion
crate.