From 67552057828206621ba6a69cb1ef272200d5ddc6 Mon Sep 17 00:00:00 2001 From: Costin-Robert Sin Date: Sun, 19 Jun 2022 02:49:07 +0300 Subject: [PATCH 1/2] Fix typo by adding a semicolon Signed-off-by: Costin-Robert Sin --- src/unistd.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unistd.rs b/src/unistd.rs index 2a8389ef7e..21fc39e697 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -608,7 +608,7 @@ fn reserve_double_buffer_size(buf: &mut Vec, limit: usize) -> Result<()> { use std::cmp::min; if buf.capacity() >= limit { - return Err(Errno::ERANGE) + return Err(Errno::ERANGE); } let capacity = min(buf.capacity() * 2, limit); From a240d82880db4edb0a8e0bb801e07ae94981c689 Mon Sep 17 00:00:00 2001 From: Costin-Robert Sin Date: Sun, 19 Jun 2022 02:52:08 +0300 Subject: [PATCH 2/2] 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 --- src/unistd.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/unistd.rs b/src/unistd.rs index 21fc39e697..5d8a56378d 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -1118,15 +1118,13 @@ pub fn lseek64(fd: RawFd, offset: libc::off64_t, whence: Whence) -> Result std::result::Result<(RawFd, RawFd), Error> { - unsafe { - let mut fds = mem::MaybeUninit::<[c_int; 2]>::uninit(); + let mut fds = mem::MaybeUninit::<[c_int; 2]>::uninit(); - let res = libc::pipe(fds.as_mut_ptr() as *mut c_int); + let res = unsafe { libc::pipe(fds.as_mut_ptr() as *mut c_int) }; - Error::result(res)?; + Error::result(res)?; - Ok((fds.assume_init()[0], fds.assume_init()[1])) - } + unsafe { Ok((fds.assume_init()[0], fds.assume_init()[1])) } } feature! {