mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
od: fix zero width user input (-w0)
This commit is contained in:
parent
92fc286b0e
commit
184c4af76d
2 changed files with 19 additions and 2 deletions
|
@ -205,12 +205,12 @@ impl OdOptions {
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
match s.parse::<usize>() {
|
match s.parse::<usize>() {
|
||||||
Ok(i) => { i }
|
Ok(i) => { i }
|
||||||
Err(_) => { 2 }
|
Err(_) => { 0 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let min_bytes = formats.iter().fold(1, |max, next| cmp::max(max, next.formatter_item_info.byte_size));
|
let min_bytes = formats.iter().fold(1, |max, next| cmp::max(max, next.formatter_item_info.byte_size));
|
||||||
if line_bytes % min_bytes != 0 {
|
if line_bytes == 0 || line_bytes % min_bytes != 0 {
|
||||||
show_warning!("invalid width {}; using {} instead", line_bytes, min_bytes);
|
show_warning!("invalid width {}; using {} instead", line_bytes, min_bytes);
|
||||||
line_bytes = min_bytes;
|
line_bytes = min_bytes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,6 +292,23 @@ fn test_invalid_width(){
|
||||||
assert_eq!(result.stdout, expected_output);
|
assert_eq!(result.stdout, expected_output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_zero_width(){
|
||||||
|
|
||||||
|
let input : [u8; 4] = [0x00, 0x00, 0x00, 0x00];
|
||||||
|
let expected_output = unindent("
|
||||||
|
0000000 000000
|
||||||
|
0000002 000000
|
||||||
|
0000004
|
||||||
|
");
|
||||||
|
|
||||||
|
let result = new_ucmd!().arg("-w0").arg("-v").run_piped_stdin(&input[..]);
|
||||||
|
|
||||||
|
assert_eq!(result.stderr, "od: warning: invalid width 0; using 2 instead\n");
|
||||||
|
assert!(result.success);
|
||||||
|
assert_eq!(result.stdout, expected_output);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_width_without_value(){
|
fn test_width_without_value(){
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue