Skip to content

Commit

Permalink
refactor to use ParseSizeError instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ic3man5 committed Mar 5, 2025
1 parent 396c002 commit 70ee1b8
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/uu/dd/src/parseargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum ParseError {
StatusLevelNotRecognized(String),
Unimplemented(String),
BsOutOfRange(String),
InvalidNumber(String),
InvalidNumber(ParseSizeError),
}

/// Contains a temporary state during parsing of the arguments
Expand Down Expand Up @@ -224,8 +224,8 @@ impl Parser {
.to_bytes(ibs as u64);
// GNU coreutils has a limit of i64 (intmax_t)
if skip > i64::MAX as u64 {
return Err(ParseError::InvalidNumber(format!(
"'{skip}': Value too large for defined data type"
return Err(ParseError::InvalidNumber(ParseSizeError::SizeTooBig(
format!("'{skip}': Value too large for defined data type"),
)));
}

Expand All @@ -235,8 +235,8 @@ impl Parser {
.to_bytes(obs as u64);
// GNU coreutils has a limit of i64 (intmax_t)
if seek > i64::MAX as u64 {
return Err(ParseError::InvalidNumber(format!(
"'{seek}': Value too large for defined data type"
return Err(ParseError::InvalidNumber(ParseSizeError::SizeTooBig(
format!("'{skip}': Value too large for defined data type"),
)));
}

Expand Down Expand Up @@ -529,7 +529,7 @@ fn parse_bytes_no_x(full: &str, s: &str) -> Result<u64, ParseError> {
(None, None, None) => match parser.parse_u64(s) {
Ok(n) => (n, 1),
Err(ParseSizeError::SizeTooBig(_)) => (u64::MAX, 1),
Err(_) => return Err(ParseError::InvalidNumber(full.to_string())),
Err(err) => return Err(ParseError::InvalidNumber(err)),
},
(Some(i), None, None) => (parse_bytes_only(s, i)?, 1),
(None, Some(i), None) => (parse_bytes_only(s, i)?, 2),
Expand Down Expand Up @@ -568,9 +568,9 @@ pub fn parse_bytes_with_opt_multiplier(s: &str) -> Result<u64, ParseError> {
show_zero_multiplier_warning();
}
let num = parse_bytes_no_x(s, part)?;
total = total
.checked_mul(num)
.ok_or_else(|| ParseError::InvalidNumber(s.to_string()))?;
total = total.checked_mul(num).ok_or_else(|| {
ParseError::InvalidNumber(ParseSizeError::ParseFailure(s.to_string()))
})?;
}
Ok(total)
}
Expand Down

0 comments on commit 70ee1b8

Please sign in to comment.