Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/uu/csplit/src/csplit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ impl SplitWriter<'_> {
// but do not rewind it either since no match should be done within.
// The consequence is that the buffer may already be full with lines from a previous
// split, which is taken care of when calling `shrink_buffer_to_size`.
let offset_usize = -offset as usize;
let offset_usize = offset.unsigned_abs() as usize;
input_iter.set_size_of_buffer(offset_usize);
while let Some((ln, line)) = input_iter.next() {
let line = line?;
Expand Down
16 changes: 16 additions & 0 deletions tests/by-util/test_csplit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,22 @@ fn test_up_to_match_negative_offset() {
assert_eq!(at.read("xx01"), generate(6, 51));
}

#[test]
fn test_up_to_match_negative_offset_min_i32() {
new_ucmd!()
.args(&["numbers50.txt", "/45/-2147483648"])
.fails()
.stderr_is("csplit: '/45/-2147483648': line number out of range\n");
}

#[test]
fn test_skip_to_match_negative_offset_min_i32() {
new_ucmd!()
.args(&["numbers50.txt", "%45%-2147483648"])
.fails()
.stderr_is("csplit: '%45%-2147483648': line number out of range\n");
}

#[test]
fn test_up_to_match_negative_offset_repeat_twice() {
let (at, mut ucmd) = at_and_ucmd!();
Expand Down
Loading