From 71dcb5f79b0e80d4e01a2ec664869ba7747f8d88 Mon Sep 17 00:00:00 2001 From: Rafael Rivera Date: Mon, 12 Feb 2024 09:03:39 -0800 Subject: [PATCH] Address new nightly unsafe precondition check panics (#2841) --- crates/libs/core/src/event.rs | 1 + crates/libs/core/src/hresult.rs | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/libs/core/src/event.rs b/crates/libs/core/src/event.rs index c63a252d42..2251edd4fd 100644 --- a/crates/libs/core/src/event.rs +++ b/crates/libs/core/src/event.rs @@ -198,6 +198,7 @@ impl Drop for Array { /// A reference-counted buffer. #[repr(C)] +#[repr(align(8))] struct Buffer(crate::imp::RefCount, std::marker::PhantomData); impl Buffer { diff --git a/crates/libs/core/src/hresult.rs b/crates/libs/core/src/hresult.rs index 8c87b67800..759d0e8cb9 100644 --- a/crates/libs/core/src/hresult.rs +++ b/crates/libs/core/src/hresult.rs @@ -86,8 +86,11 @@ impl HRESULT { unsafe { let size = crate::imp::FormatMessageW(crate::imp::FORMAT_MESSAGE_ALLOCATE_BUFFER | crate::imp::FORMAT_MESSAGE_FROM_SYSTEM | crate::imp::FORMAT_MESSAGE_IGNORE_INSERTS, std::ptr::null(), self.0 as u32, 0, &mut message.0 as *mut _ as *mut _, 0, std::ptr::null()); - - HSTRING::from_wide(crate::imp::wide_trim_end(std::slice::from_raw_parts(message.0 as *const u16, size as usize))).unwrap_or_default() + if !message.0.is_null() && size > 0 { + HSTRING::from_wide(crate::imp::wide_trim_end(std::slice::from_raw_parts(message.0 as *const u16, size as usize))).unwrap_or_default() + } else { + HSTRING::default() + } } }