Skip to content

Commit 39c3646

Browse files
oech3cakebaker
authored andcommitted
tee: restore alloc guard for small input
1 parent fd781df commit 39c3646

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/uu/tee/src/tee.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,14 @@ impl MultiWriter {
159159
// https://github.com/rust-lang/rust/blob/2feb91181882e525e698c4543063f4d0296fcf91/library/std/src/sys/io/mod.rs#L44
160160
const BUF_SIZE: usize = 8 * 1024;
161161
let mut buffer = [0u8; BUF_SIZE];
162-
// fast-path for small input
163-
match input.read(&mut buffer) {
164-
Ok(0) => return Ok(()), // end of file
165-
Ok(received) => self.write_flush(&buffer[..received])?,
166-
Err(e) if e.kind() != ErrorKind::Interrupted => return Err(e),
167-
_ => {}
162+
// fast-path for small input. needs 2+ read to catch end of file
163+
for _ in 0..2 {
164+
match input.read(&mut buffer) {
165+
Ok(0) => return Ok(()), // end of file
166+
Ok(received) => self.write_flush(&buffer[..received])?,
167+
Err(e) if e.kind() != ErrorKind::Interrupted => return Err(e),
168+
_ => {}
169+
}
168170
}
169171
// buffer is too small optimize for large input
170172
//stack array makes code path for smaller file slower

0 commit comments

Comments
 (0)