Skip to content

Commit b6df05d

Browse files
bors[bot]costinsin
andauthored
Merge #1746
1746: Fix typo and minimise the use of `unsafe` blocks inside the `pipe` function r=rtzoeller a=costinsin Some of the operations inside the pipe function are safe and should not be included inside an unsafe block. Co-authored-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
2 parents 01a5927 + a240d82 commit b6df05d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/unistd.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ fn reserve_double_buffer_size<T>(buf: &mut Vec<T>, limit: usize) -> Result<()> {
608608
use std::cmp::min;
609609

610610
if buf.capacity() >= limit {
611-
return Err(Errno::ERANGE)
611+
return Err(Errno::ERANGE);
612612
}
613613

614614
let capacity = min(buf.capacity() * 2, limit);
@@ -1118,15 +1118,13 @@ pub fn lseek64(fd: RawFd, offset: libc::off64_t, whence: Whence) -> Result<libc:
11181118
///
11191119
/// See also [pipe(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pipe.html)
11201120
pub fn pipe() -> std::result::Result<(RawFd, RawFd), Error> {
1121-
unsafe {
1122-
let mut fds = mem::MaybeUninit::<[c_int; 2]>::uninit();
1121+
let mut fds = mem::MaybeUninit::<[c_int; 2]>::uninit();
11231122

1124-
let res = libc::pipe(fds.as_mut_ptr() as *mut c_int);
1123+
let res = unsafe { libc::pipe(fds.as_mut_ptr() as *mut c_int) };
11251124

1126-
Error::result(res)?;
1125+
Error::result(res)?;
11271126

1128-
Ok((fds.assume_init()[0], fds.assume_init()[1]))
1129-
}
1127+
unsafe { Ok((fds.assume_init()[0], fds.assume_init()[1])) }
11301128
}
11311129

11321130
feature! {

0 commit comments

Comments
 (0)