mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-08-18 21:53:48 -07:00
stats: fix case where "bytes searched" could be wrong
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
This commit is contained in:
@@ -37,7 +37,11 @@ where
|
||||
|
||||
pub(crate) fn run(mut self) -> Result<(), S::Error> {
|
||||
if self.core.begin()? {
|
||||
while self.fill()? && self.core.match_by_line(self.rdr.buffer())? {
|
||||
while self.fill()? {
|
||||
if !self.core.match_by_line(self.rdr.buffer())? {
|
||||
self.consume_remaining();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.core.finish(
|
||||
@@ -46,6 +50,11 @@ where
|
||||
)
|
||||
}
|
||||
|
||||
fn consume_remaining(&mut self) {
|
||||
let consumed = self.core.pos();
|
||||
self.rdr.consume(consumed);
|
||||
}
|
||||
|
||||
fn fill(&mut self) -> Result<bool, S::Error> {
|
||||
assert!(self.rdr.buffer()[self.core.pos()..].is_empty());
|
||||
|
||||
|
Reference in New Issue
Block a user