Skip to content
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

Remove some uses of mem::uninitialized #62422

Merged
merged 3 commits into from
Jul 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/librustc_codegen_llvm/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ impl CodegenCx<'ll, 'tcx> {
pub fn const_get_real(&self, v: &'ll Value) -> Option<(f64, bool)> {
unsafe {
if self.is_const_real(v) {
#[allow(deprecated)]
let mut loses_info: llvm::Bool = ::std::mem::uninitialized();
let mut loses_info: llvm::Bool = 0;
let r = llvm::LLVMConstRealGetDouble(v, &mut loses_info);
let loses_info = if loses_info == 1 { true } else { false };
Some((r, loses_info))
Expand Down
38 changes: 29 additions & 9 deletions src/libterm/win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

// FIXME (#13400): this is only a tiny fraction of the Windows console api

extern crate libc;

use std::io;
use std::io::prelude::*;

Expand All @@ -20,19 +18,36 @@ pub struct WinConsole<T> {
background: color::Color,
}

type SHORT = i16;
type WORD = u16;
type DWORD = u32;
type BOOL = i32;
type HANDLE = *mut u8;

#[allow(non_snake_case)]
#[repr(C)]
struct SMALL_RECT {
Left: SHORT,
Top: SHORT,
Right: SHORT,
Bottom: SHORT,
}

#[allow(non_snake_case)]
#[repr(C)]
struct COORD {
X: SHORT,
Y: SHORT,
}

#[allow(non_snake_case)]
#[repr(C)]
struct CONSOLE_SCREEN_BUFFER_INFO {
dwSize: [libc::c_short; 2],
dwCursorPosition: [libc::c_short; 2],
dwSize: COORD,
dwCursorPosition: COORD,
wAttributes: WORD,
srWindow: [libc::c_short; 4],
dwMaximumWindowSize: [libc::c_short; 2],
srWindow: SMALL_RECT,
dwMaximumWindowSize: COORD,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is all of this diff about?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make CONSOLE_SCREEN_BUFFER_INFO definition like the one in winapi.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I can review Windows FFI code I am afraid. I can't even remember how big a DWORD is.

}

#[allow(non_snake_case)]
Expand Down Expand Up @@ -105,12 +120,17 @@ impl<T: Write + Send + 'static> WinConsole<T> {

/// Returns `None` whenever the terminal cannot be created for some reason.
pub fn new(out: T) -> io::Result<WinConsole<T>> {
use std::mem::MaybeUninit;

let fg;
let bg;
unsafe {
#[allow(deprecated)]
let mut buffer_info = ::std::mem::uninitialized();
if GetConsoleScreenBufferInfo(GetStdHandle(-11i32 as DWORD), &mut buffer_info) != 0 {
let mut buffer_info = MaybeUninit::<CONSOLE_SCREEN_BUFFER_INFO>::uninit();
if GetConsoleScreenBufferInfo(
GetStdHandle(-11i32 as DWORD),
buffer_info.as_mut_ptr()
) != 0 {
let buffer_info = buffer_info.assume_init() ;
fg = bits_to_color(buffer_info.wAttributes);
bg = bits_to_color(buffer_info.wAttributes >> 4);
} else {
Expand Down