diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index e1d7b0ad6..6c7ce253d 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -1166,10 +1166,6 @@ fn dd_copy(mut i: Input, o: Output) -> io::Result<()> { ); } - // Create a common buffer with a capacity of the block size. - // This is the max size needed. - let mut buf = vec![BUF_INIT_BYTE; bsize]; - // Spawn a timer thread to provide a scheduled signal indicating when we // should send an update of our progress to the reporting thread. // @@ -1201,6 +1197,11 @@ fn dd_copy(mut i: Input, o: Output) -> io::Result<()> { BlockWriter::Unbuffered(o) }; + // Create a common empty buffer with a capacity of the block size. + // This is the max size needed. + let mut buf = Vec::new(); + buf.try_reserve(bsize)?; // try_with_capacity is unstable https://github.com/rust-lang/rust/issues/91913 + // The main read/write loop. // // Each iteration reads blocks from the input and writes @@ -1366,6 +1367,7 @@ fn read_helper(i: &mut Input, buf: &mut Vec, bsize: usize) -> io::Result