Skip to content

Commit

Permalink
cut: fail when the input == usize::MAX
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Sep 24, 2023
1 parent 31d32e3 commit 0cb60d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/uucore/src/lib/features/ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ impl FromStr for Range {
fn parse(s: &str) -> Result<usize, &'static str> {
match s.parse::<usize>() {
Ok(0) => Err("fields and positions are numbered from 1"),
// GNU fails when we are at the limit. Match their behavior
Ok(n) if n >= usize::MAX => Err("byte/character offset is too large"),
Ok(n) => Ok(n),
Err(_) => Err("failed to parse range"),
}
Expand Down
8 changes: 8 additions & 0 deletions tests/by-util/test_cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ fn test_whitespace_with_char() {
.code_is(1);
}

#[test]
fn test_too_large() {
new_ucmd!()
.args(&["-b1-18446744073709551615", "/dev/null"])
.fails()
.code_is(1);
}

#[test]
fn test_specify_delimiter() {
for param in ["-d", "--delimiter", "--del"] {
Expand Down

0 comments on commit 0cb60d1

Please sign in to comment.