1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

cut: fail when the input == usize::MAX

This commit is contained in:
Sylvestre Ledru 2023-09-24 23:13:34 +02:00
parent 4038907de6
commit 99120d32c1
2 changed files with 10 additions and 0 deletions

View file

@ -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"),
}

View file

@ -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"] {