Skip to content

Commit 236e220

Browse files
authored
yes: dedup the logic for buffer creation, improve assertion (#11536)
1 parent 5f9f735 commit 236e220

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

src/uu/yes/src/yes.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,9 @@ fn args_into_buffer<'a>(
9292
/// Assumes buf holds a single output line forged from the command line arguments, copies it
9393
/// repeatedly until the buffer holds as many copies as it can under [`BUF_SIZE`].
9494
fn prepare_buffer(buf: &mut Vec<u8>) {
95-
if buf.len() * 2 > BUF_SIZE {
96-
return;
97-
}
98-
99-
assert!(!buf.is_empty());
100-
10195
let line_len = buf.len();
102-
let target_size = line_len * (BUF_SIZE / line_len);
96+
debug_assert!(line_len > 0, "buffer is not empty since we have newline");
97+
let target_size = line_len * (BUF_SIZE / line_len); // 0 if line_len is already large enough
10398

10499
while buf.len() < target_size {
105100
let to_copy = std::cmp::min(target_size - buf.len(), buf.len());

0 commit comments

Comments
 (0)