Stebalien / term

A Rust library for terminfo parsing and terminal colors.
https://stebalien.github.io/doc/term/term/
Apache License 2.0
178 stars 49 forks source link

Use mem::MaybeUninit instead of mem::uninitialized() since Rust 1.36 #101

Closed rhysd closed 5 years ago

rhysd commented 5 years ago

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 replaces std::mem::uninitialized() using a compiler version switch provided by rustversion crate.

rhysd commented 5 years ago

I have addressed the review comment at 8edc0474dd4d27b0af055feefb583794dad4b3f2. Instead of uninitialized(), it wraps GetConsoleScreenBufferInfo() as get_console_screen_buffer_info(). After getting uninitialized memory, it immediately initializes the buffer with GetConsoleScreenBufferInfo(). So the returned buffer is guaranteed to be initialized and there is no undefined behavior.

(I apologize many force pushes. I don't have Windows machine so I needed to check Appveyor result instead)

rhysd commented 5 years ago

Ahh, ok, I misunderstood the semantics of MaybeUninit. Thank you for the point.

rhysd commented 5 years ago

I fixed my patch again at 3e9624f and added a new small test for get_console_screen_buffer_info() at 65801a0.

rhysd commented 5 years ago

Thank you for correcting me and helping to understand correctly.