Skip to content

Commit db9a111

Browse files
authored
dd: do not show zero multiplier warning when zero is the multiplicand (#11673)
* dd: do not show zero multiplier warning when zero is the multiplicand * tests/dd: test zero multiplier warning when zero is the multiplicand
1 parent fca0d04 commit db9a111

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/uu/dd/src/parseargs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,8 @@ pub fn parse_bytes_with_opt_multiplier(s: &str) -> Result<u64, ParseError> {
524524
parse_bytes_no_x(s, parts[0])
525525
} else {
526526
let mut total: u64 = 1;
527-
for part in parts {
528-
if part == "0" {
527+
for (i, part) in parts.iter().enumerate() {
528+
if *part == "0" && i != parts.len() - 1 {
529529
show_zero_multiplier_warning();
530530
}
531531
let num = parse_bytes_no_x(s, part)?;

tests/by-util/test_dd.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,13 @@ fn test_zero_multiplier_warning() {
263263
.succeeds()
264264
.no_stdout()
265265
.stderr_contains("warning: '0x' is a zero multiplier; use '00x' if that is intended");
266+
267+
new_ucmd!()
268+
.args(&[format!("{arg}=0x0x0").as_str(), "status=none"])
269+
.pipe_in("")
270+
.succeeds()
271+
.no_stdout()
272+
.stderr_is("dd: warning: '0x' is a zero multiplier; use '00x' if that is intended\ndd: warning: '0x' is a zero multiplier; use '00x' if that is intended\n");
266273
}
267274
}
268275

0 commit comments

Comments
 (0)