From 17c07bd8eb9cb41b6e285a86d324bd47a7ce7bc7 Mon Sep 17 00:00:00 2001 From: Cannnabis Date: Sat, 28 Nov 2026 02:39:47 +0700 Subject: [PATCH] book: the address a device loss names can be any u64 neighbours() added one to it directly, so u64::MAX panicked in a debug build and wrapped past the range start in a release one: the loss report aborted instead of naming what was near. The module's lower bounds already saturate; the upper one does now too, and the book test asks for the top address. (cherry picked from commit 18632ec2b639a04c83e5bd74449e12bf28731e93) --- crates/victory-gpu/src/book.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/victory-gpu/src/book.rs b/crates/victory-gpu/src/book.rs index 87de67d..b8b8b4e 100644 --- a/crates/victory-gpu/src/book.rs +++ b/crates/victory-gpu/src/book.rs @@ -146,7 +146,9 @@ impl Book { /// The live entry that starts last at or below `at`, and the next above. fn neighbours(&self, at: u64) -> [Option<&Entry>; 2] { let below = self.by_start.range(..=(at, u64::MAX)).next_back(); - let above = self.by_start.range((at + 1, 0)..).next(); + // Saturating, as the lower bounds above: `at` is an address the + // card reported, any u64. + let above = self.by_start.range((at.saturating_add(1), 0)..).next(); [below, above].map(|e| e.and_then(|((_, id), ())| self.live.get(id))) } @@ -748,5 +750,7 @@ mod tests { assert_eq!(b.neighbours(0x1000_0100)[1].map(|e| e.what.as_str()), Some("two")); b.remove(two, 3, 13); assert!(b.neighbours(u64::MAX - 1)[0].is_none() && b.by_object.is_empty()); + // An address the card reports can be anything, the top one included. + assert!(b.neighbours(u64::MAX)[0].is_none() && b.neighbours(u64::MAX)[1].is_none()); } }