Skip to content
Myr

stats: fix case where "bytes searched" could be wrong

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Specifically, if the search was instructed to quit early, we might not have correctly marked the number of bytes consumed. I don't think this bug occurs when memory maps are used to read the haystack. Closes #2944

authored by Andrew Gallant · committed by Andrew Gallant · parent 6244e63 · Browse files · 3 files+19 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+19 added−1 removed

  • tests:+7 added−0 removed
  • other:+12 added−1 removed

3 files+19 added−1 removed

modified:crates/searcher/src/searcher/glue.rs+10 added-1 removed
35 unmodified lines
36 }3738 pub(crate) fn run(mut self) -> Result<(), S::Error> {39 if self.core.begin()? {40 while self.fill()? && self.core.match_by_line(self.rdr.buffer())? {40 while self.fill()? {41 if !self.core.match_by_line(self.rdr.buffer())? {42 self.consume_remaining();43 break;44 }45 }46 }47 self.core.finish(48 self.rdr.absolute_byte_offset(),49 self.rdr.binary_byte_offset(),50 )51 }5253 fn consume_remaining(&mut self) {54 let consumed = self.core.pos();55 self.rdr.consume(consumed);56 }5758 fn fill(&mut self) -> Result<bool, S::Error> {59 assert!(self.rdr.buffer()[self.core.pos()..].is_empty());6061 let already_binary = self.rdr.binary_byte_offset().is_some();
1490 unmodified lines
modified:tests/regression.rs+7 added
1452 unmodified lines
1453 dir.create("haystack", "foo\0bar\0quux\0");1454 let got = cmd.args(&["--null-data", "--line-regexp", r"bar"]).stdout();1455 eqnice!("haystack:bar\0", got);1456});14571458// See: https://github.com/BurntSushi/ripgrep/pull/29441459rgtest!(r2944_incorrect_bytes_searched, |dir: Dir, mut cmd: TestCommand| {1460 dir.create("haystack", "foo1\nfoo2\nfoo3\nfoo4\nfoo5\n");1461 let got = cmd.args(&["--stats", "-m2", "foo", "."]).stdout();1462 assert!(got.contains("10 bytes searched\n"));1463});
modified:CHANGELOG.md+2 added
19 unmodified lines
20 [BUG #3001](https://github.com/BurntSushi/ripgrep/issues/3001):21 Make `rg -vf file` where `file` is empty match everything.22* [BUG #2177](https://github.com/BurntSushi/ripgrep/issues/2177):23 Ignore a UTF-8 BOM marker at the start of `.gitignore` (and similar files).24* [BUG #2944](https://github.com/BurntSushi/ripgrep/pull/2944):25 Fix a bug where the "bytes searched" in `--stats` output could be incorrect.2627Feature enhancements:2829* Many enhancements to the default set of file types available for filtering.
1727 unmodified lines