File tree 1 file changed +14
-12
lines changed
1 file changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -55,20 +55,22 @@ pub fn sys_fill_exact(
55
55
) -> Result < ( ) , Error > {
56
56
while !buf. is_empty ( ) {
57
57
let res = sys_fill ( buf) ;
58
- match res {
59
- res if res > 0 => buf = buf. get_mut ( res as usize ..) . ok_or ( Error :: UNEXPECTED ) ?,
60
- -1 => {
61
- let err = last_os_error ( ) ;
62
- // We should try again if the call was interrupted.
63
- if err. raw_os_error ( ) != Some ( libc:: EINTR ) {
64
- return Err ( err) ;
65
- }
58
+ if let Ok ( res) = usize:: try_from ( res) {
59
+ if res > 0 {
60
+ buf = buf. get_mut ( res..) . ok_or ( Error :: UNEXPECTED ) ?;
61
+ continue ;
62
+ }
63
+ } else if res == -1 {
64
+ let err = last_os_error ( ) ;
65
+ // We should try again if the call was interrupted.
66
+ if err. raw_os_error ( ) != Some ( libc:: EINTR ) {
67
+ return Err ( err) ;
66
68
}
67
- // Negative return codes not equal to -1 should be impossible.
68
- // EOF (ret = 0) should be impossible, as the data we are reading
69
- // should be an infinite stream of random bytes.
70
- _ => return Err ( Error :: UNEXPECTED ) ,
71
69
}
70
+ // Negative return codes not equal to -1 should be impossible.
71
+ // EOF (ret = 0) should be impossible, as the data we are reading
72
+ // should be an infinite stream of random bytes.
73
+ return Err ( Error :: UNEXPECTED ) ;
72
74
}
73
75
Ok ( ( ) )
74
76
}
You can’t perform that action at this time.
0 commit comments