diff --git a/src/controller.rs b/src/controller.rs index d9ed4b795b..83944dd6b6 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -261,7 +261,8 @@ impl Controller<'_> { // Buffer needs to be 1 greater than the offset to have a look-ahead line for EOF let buffer_size: usize = line_ranges.largest_offset_from_end() + 1; // Buffers multiple line data and line number - let mut buffered_lines: VecDeque<(Vec, usize)> = VecDeque::with_capacity(buffer_size); + let mut buffered_lines: VecDeque<(Vec, usize)> = + VecDeque::with_capacity(buffer_size.min(1024)); let mut reached_eof: bool = false; let mut first_range: bool = true; diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 5d682c8cc2..31a301a17b 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -576,6 +576,16 @@ fn line_range_context_very_large() { ); } +#[test] +fn line_range_huge_negative_does_not_panic() { + bat() + .arg("multiline.txt") + .arg("--line-range=:-999999999999999999") + .assert() + .success() + .stdout(""); +} + #[test] fn piped_output_with_implicit_auto_style() { bat() @@ -585,6 +595,15 @@ fn piped_output_with_implicit_auto_style() { .stdout("hello\nworld\n"); } +#[test] +fn piped_output_with_line_range() { + bat() + .arg("--line-range=2:3") + .write_stdin("line 1\nline 2\nline 3\nline 4\n") + .assert() + .success() + .stdout("line 2\nline 3\n"); +} #[test] fn piped_output_with_line_number_flag() { bat()