From 5c27cebeac81f3405855ad050c7f962f982806b4 Mon Sep 17 00:00:00 2001 From: peamaeq <104552320+peamaeq@users.noreply.github.com> Date: Thu, 7 Mar 2024 13:14:44 +0800 Subject: [PATCH] 0503 (#24) --- src/map.rs | 12 ++++-------- src/os/windows.rs | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/map.rs b/src/map.rs index 1d1686f..4e96b58 100644 --- a/src/map.rs +++ b/src/map.rs @@ -99,13 +99,11 @@ impl Map { /// # } /// ``` pub fn into_map_mut(self) -> ConvertResult { - unsafe { - let (ptr, len) = Size::page().bounds(self.0.ptr, self.0.len); - match protect(ptr, len, Protect::ReadWrite) { + let (ptr, len) = unsafe { Size::page().bounds(self.0.ptr, self.0.len) }; + match unsafe { protect(ptr, len, Protect::ReadWrite) }{ Ok(()) => Ok(self.0), Err(err) => Err((err, self)), } - } } /// Updates the advise for the entire mapped region.. @@ -292,13 +290,11 @@ impl MapMut { /// # } /// ``` pub fn into_map(self) -> ConvertResult { - unsafe { - let (ptr, len) = Size::page().bounds(self.ptr, self.len); - match protect(ptr, len, Protect::ReadWrite) { + let (ptr, len) = unsafe { Size::page().bounds(self.ptr, self.len) }; + match unsafe { protect(ptr, len, Protect::ReadWrite) }{ Ok(()) => Ok(Map(self)), Err(err) => Err((err, self)), } - } } /// Writes modifications back to the filesystem. diff --git a/src/os/windows.rs b/src/os/windows.rs index a601dba..60b701d 100644 --- a/src/os/windows.rs +++ b/src/os/windows.rs @@ -89,8 +89,8 @@ impl Drop for MapHandle { /// Requests the page size and allocation granularity from the system. pub fn system_info() -> (u32, u32) { + let mut info = mem::MaybeUninit::::uninit(); let info = unsafe { - let mut info = mem::MaybeUninit::::uninit(); GetSystemInfo(info.as_mut_ptr() as LPSYSTEM_INFO); info.assume_init() };