From 97d438cd314d33c976cc0bb7fbfa08150270cbe2 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 9 Sep 2022 15:01:26 +0200 Subject: [PATCH] Use Align8 to avoid misalignment if the allocator or Vec doesn't align allocations --- library/std/src/sys/windows/io.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/library/std/src/sys/windows/io.rs b/library/std/src/sys/windows/io.rs index 7e7518b6d89..0879ef19933 100644 --- a/library/std/src/sys/windows/io.rs +++ b/library/std/src/sys/windows/io.rs @@ -2,7 +2,7 @@ use crate::marker::PhantomData; use crate::mem::size_of; use crate::os::windows::io::{AsHandle, AsRawHandle, BorrowedHandle}; use crate::slice; -use crate::sys::c; +use crate::sys::{c, Align8}; use core; use libc; @@ -120,21 +120,21 @@ unsafe fn handle_is_console(handle: BorrowedHandle<'_>) -> bool { } unsafe fn msys_tty_on(handle: c::HANDLE) -> bool { - let size = size_of::() + c::MAX_PATH * size_of::(); - let mut name_info_bytes = vec![0u8; size]; + const SIZE: usize = size_of::() + c::MAX_PATH * size_of::(); + let mut name_info_bytes = Align8([0u8; SIZE]); let res = c::GetFileInformationByHandleEx( handle, c::FileNameInfo, - name_info_bytes.as_mut_ptr() as *mut libc::c_void, - size as u32, + name_info_bytes.0.as_mut_ptr() as *mut libc::c_void, + SIZE as u32, ); if res == 0 { return false; } - let name_info: &c::FILE_NAME_INFO = &*(name_info_bytes.as_ptr() as *const c::FILE_NAME_INFO); + let name_info: &c::FILE_NAME_INFO = &*(name_info_bytes.0.as_ptr() as *const c::FILE_NAME_INFO); let name_len = name_info.FileNameLength as usize / 2; // Offset to get the `FileName` field. - let name_ptr = name_info_bytes.as_ptr().offset(size_of::() as isize).cast::(); + let name_ptr = name_info_bytes.0.as_ptr().offset(size_of::() as isize).cast::(); let s = core::slice::from_raw_parts(name_ptr, name_len); let name = String::from_utf16_lossy(s); // This checks whether 'pty' exists in the file name, which indicates that