Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit417b61f

Browse files
committed
Narrow the scope of the ReadFile unsafe block
1 parentb4d1392 commit417b61f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

‎std/src/sys/pal/windows/handle.rs‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl Handle {
143143
) -> io::Result<Option<usize>>{
144144
// SAFETY: We have exclusive access to the buffer and it's up to the caller to
145145
// ensure the OVERLAPPED pointer is valid for the lifetime of this function.
146-
unsafe{
146+
let(res, amt) =unsafe{
147147
let len = cmp::min(buf.len(), u32::MAXasusize)asu32;
148148
letmut amt =0;
149149
let res =cvt(c::ReadFile(
@@ -153,16 +153,17 @@ impl Handle {
153153
&mut amt,
154154
overlapped,
155155
));
156-
match res{
157-
Ok(_) =>Ok(Some(amtasusize)),
158-
Err(e) =>{
159-
if e.raw_os_error() ==Some(c::ERROR_IO_PENDINGasi32){
160-
Ok(None)
161-
}elseif e.raw_os_error() ==Some(c::ERROR_BROKEN_PIPEasi32){
162-
Ok(Some(0))
163-
}else{
164-
Err(e)
165-
}
156+
(res, amt)
157+
};
158+
match res{
159+
Ok(_) =>Ok(Some(amtasusize)),
160+
Err(e) =>{
161+
if e.raw_os_error() ==Some(c::ERROR_IO_PENDINGasi32){
162+
Ok(None)
163+
}elseif e.raw_os_error() ==Some(c::ERROR_BROKEN_PIPEasi32){
164+
Ok(Some(0))
165+
}else{
166+
Err(e)
166167
}
167168
}
168169
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp