mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
head: fix subtraction underflow with --bytes=-N
Fix a subtraction underflow that occurred on `head --bytes=-N` when the input had fewer than `N` bytes. Before this commit, printf "a" | head -c -2 would panic. After this commit, it terminates successfully with no output as expected.
This commit is contained in:
parent
00d1866060
commit
c9acf5ddd4
2 changed files with 19 additions and 1 deletions
|
@ -157,6 +157,23 @@ fn test_negative_byte_syntax() {
|
|||
.stdout_is("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_negative_bytes_greater_than_input_size_stdin() {
|
||||
new_ucmd!()
|
||||
.args(&["-c", "-2"])
|
||||
.pipe_in("a")
|
||||
.succeeds()
|
||||
.no_output();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_negative_bytes_greater_than_input_size_file() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
at.write_bytes("f", b"a");
|
||||
ts.ucmd().args(&["-c", "-2", "f"]).succeeds().no_output();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_negative_zero_lines() {
|
||||
new_ucmd!()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue