mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #3085 from jfinkels/dd-zero-multiplier
dd: show warning when using 0x size multiplier
This commit is contained in:
commit
4d07083bac
2 changed files with 41 additions and 0 deletions
|
@ -13,6 +13,7 @@ use super::*;
|
|||
use std::error::Error;
|
||||
use uucore::error::UError;
|
||||
use uucore::parse_size::ParseSizeError;
|
||||
use uucore::show_warning;
|
||||
|
||||
pub type Matches = ArgMatches;
|
||||
|
||||
|
@ -356,6 +357,13 @@ fn parse_bytes_only(s: &str) -> Result<usize, ParseError> {
|
|||
/// assert_eq!(parse_bytes_no_x("2k").unwrap(), 2 * 1024);
|
||||
/// ```
|
||||
fn parse_bytes_no_x(s: &str) -> Result<usize, ParseError> {
|
||||
if s == "0" {
|
||||
show_warning!(
|
||||
"{} is a zero multiplier; use {} if that is intended",
|
||||
"0x".quote(),
|
||||
"00x".quote()
|
||||
);
|
||||
}
|
||||
let (num, multiplier) = match (s.find('c'), s.rfind('w'), s.rfind('b')) {
|
||||
(None, None, None) => match uucore::parse_size::parse_size(s) {
|
||||
Ok(n) => (n, 1),
|
||||
|
|
|
@ -198,6 +198,39 @@ fn test_x_multiplier() {
|
|||
.stdout_is("abcdef");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zero_multiplier_warning() {
|
||||
for arg in ["count", "seek", "skip"] {
|
||||
new_ucmd!()
|
||||
.args(&[format!("{}=00x1", arg).as_str(), "status=none"])
|
||||
.pipe_in("")
|
||||
.succeeds()
|
||||
.no_stdout()
|
||||
.no_stderr();
|
||||
|
||||
new_ucmd!()
|
||||
.args(&[format!("{}=0x1", arg).as_str(), "status=none"])
|
||||
.pipe_in("")
|
||||
.succeeds()
|
||||
.no_stdout()
|
||||
.stderr_contains("warning: '0x' is a zero multiplier; use '00x' if that is intended");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&[format!("{}=0x0x1", arg).as_str(), "status=none"])
|
||||
.pipe_in("")
|
||||
.succeeds()
|
||||
.no_stdout()
|
||||
.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");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&[format!("{}=1x0x1", arg).as_str(), "status=none"])
|
||||
.pipe_in("")
|
||||
.succeeds()
|
||||
.no_stdout()
|
||||
.stderr_contains("warning: '0x' is a zero multiplier; use '00x' if that is intended");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_final_stats_noxfer() {
|
||||
new_ucmd!()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue