Skip to content

Commit

Permalink
Reason safety for unsafe blocks for uwp stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
bdbai committed Sep 22, 2021
1 parent a8ac6d4 commit 4e01157
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions library/std/src/sys/windows/stdio_uwp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn get_handle(handle_id: c::DWORD) -> io::Result<c::HANDLE> {

fn write(handle_id: c::DWORD, data: &[u8]) -> io::Result<usize> {
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)
}
Expand All @@ -39,6 +40,7 @@ impl Stdin {
impl io::Read for Stdin {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
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)
}
Expand Down

0 comments on commit 4e01157

Please sign in to comment.