mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-16 14:07:04 +00:00
Reason safety for unsafe blocks for uwp stdin
This commit is contained in:
parent
a8ac6d471e
commit
4e01157969
@ -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)
|
||||
}
|
||||
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user