Skip to content

Commit a240d82

Browse files
committed
Minimise the use of the unsafe block inside pipe function
Some of the operations inside the pipe function are safe and should not be included inside an unsafe block. Signed-off-by: Costin-Robert Sin <[email protected]>
1 parent 6755205 commit a240d82

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/unistd.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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)