From 020124b5a63663fb9591d3b6a5dbd4ed5fe8946b Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Sat, 25 Apr 2026 12:40:17 +0900 Subject: [PATCH] wc: Fix fallback when pipe() or splice() failed --- src/uu/wc/src/count_fast.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/uu/wc/src/count_fast.rs b/src/uu/wc/src/count_fast.rs index 2df9efc00..6e0d34fae 100644 --- a/src/uu/wc/src/count_fast.rs +++ b/src/uu/wc/src/count_fast.rs @@ -48,7 +48,7 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result { // - sender without splice is bottleneck of our wc -c loop { match splice(fd, &null_file, MAX_ROOTLESS_PIPE_SIZE) { - Ok(0) => break, + Ok(0) => return Ok(byte_count), Ok(res) => byte_count += res, Err(_) => return Err(byte_count), } @@ -57,7 +57,7 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result { // input is not pipe. needs broker to use splice() with additional cost loop { match splice(fd, &pipe_wr, MAX_ROOTLESS_PIPE_SIZE) { - Ok(0) => break, + Ok(0) => return Ok(byte_count), Ok(res) => { byte_count += res; splice_exact(&pipe_rd, &null_file, res).map_err(|_| byte_count)?; @@ -66,10 +66,8 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result { } } } else { - return Ok(0_usize); + Err(0) } - - Ok(byte_count) } /// In the special case where we only need to count the number of bytes. There