From 4e01157969eb5726f08fa31a898108654d813fdd Mon Sep 17 00:00:00 2001 From: bdbai Date: Thu, 23 Sep 2021 07:29:52 +0800 Subject: [PATCH] Reason safety for unsafe blocks for uwp stdin --- library/std/src/sys/windows/stdio_uwp.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/std/src/sys/windows/stdio_uwp.rs b/library/std/src/sys/windows/stdio_uwp.rs index 31ffa8c95718d..32550f796ec64 100644 --- a/library/std/src/sys/windows/stdio_uwp.rs +++ b/library/std/src/sys/windows/stdio_uwp.rs @@ -26,6 +26,7 @@ pub fn get_handle(handle_id: c::DWORD) -> io::Result { fn write(handle_id: c::DWORD, data: &[u8]) -> io::Result { let handle = get_handle(handle_id)?; + // SAFETY: The handle returned from `get_handle` must be valid and non-null. let handle = unsafe { Handle::from_raw_handle(handle) }; ManuallyDrop::new(handle).write(data) } @@ -39,6 +40,7 @@ impl Stdin { impl io::Read for Stdin { fn read(&mut self, buf: &mut [u8]) -> io::Result { let handle = get_handle(c::STD_INPUT_HANDLE)?; + // SAFETY: The handle returned from `get_handle` must be valid and non-null. let handle = unsafe { Handle::from_raw_handle(handle) }; ManuallyDrop::new(handle).read(buf) }