about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tvix/castore/src/refscan.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/tvix/castore/src/refscan.rs b/tvix/castore/src/refscan.rs
index 0b8af296bb50..8e6a81b2a4fe 100644
--- a/tvix/castore/src/refscan.rs
+++ b/tvix/castore/src/refscan.rs
@@ -192,7 +192,15 @@ where
         self: Pin<&mut Self>,
         cx: &mut std::task::Context<'_>,
     ) -> Poll<std::io::Result<&[u8]>> {
-        let overlap = self.scanner.pattern.longest_candidate() - 1;
+        #[allow(clippy::manual_saturating_arithmetic)] // for clarity
+        let overlap = self
+            .scanner
+            .pattern
+            .longest_candidate()
+            .checked_sub(1)
+            // If this overflows (longest_candidate = 0), that means there are no needles,
+            // so there is no need to have any overlap
+            .unwrap_or(0);
         let mut this = self.project();
         // Still data in buffer
         if *this.consumed < this.buffer.len() {