1
Fork 0

Narrow the scope of the ReadFile unsafe block

This commit is contained in:
Chris Denton 2024-07-17 05:53:20 +00:00
parent a33abbba98
commit 2043de12a3
No known key found for this signature in database
GPG key ID: 713472F2F45627DE

View file

@ -143,7 +143,7 @@ impl Handle {
) -> io::Result<Option<usize>> { ) -> io::Result<Option<usize>> {
// SAFETY: We have exclusive access to the buffer and it's up to the caller to // SAFETY: We have exclusive access to the buffer and it's up to the caller to
// ensure the OVERLAPPED pointer is valid for the lifetime of this function. // ensure the OVERLAPPED pointer is valid for the lifetime of this function.
unsafe { let (res, amt) = unsafe {
let len = cmp::min(buf.len(), u32::MAX as usize) as u32; let len = cmp::min(buf.len(), u32::MAX as usize) as u32;
let mut amt = 0; let mut amt = 0;
let res = cvt(c::ReadFile( let res = cvt(c::ReadFile(
@ -153,6 +153,8 @@ impl Handle {
&mut amt, &mut amt,
overlapped, overlapped,
)); ));
(res, amt)
};
match res { match res {
Ok(_) => Ok(Some(amt as usize)), Ok(_) => Ok(Some(amt as usize)),
Err(e) => { Err(e) => {
@ -166,7 +168,6 @@ impl Handle {
} }
} }
} }
}
pub fn overlapped_result( pub fn overlapped_result(
&self, &self,