From b475d40910495fcd8e69a404ba72f654751c9024 Mon Sep 17 00:00:00 2001 From: Intege-rs Date: Sat, 13 Sep 2025 22:27:32 -0400 Subject: [PATCH] Properly support ranges on hex dump --- sub/xpat/src/hexdump.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sub/xpat/src/hexdump.rs b/sub/xpat/src/hexdump.rs index 6577879..ec6e539 100644 --- a/sub/xpat/src/hexdump.rs +++ b/sub/xpat/src/hexdump.rs @@ -7,13 +7,12 @@ const SEP: &str = " | "; pub struct HexDump<'s, T: Scannable + ?Sized, R: RangeBounds>(pub &'s T, pub R); pub fn hex< - 's, T: Scannable + ?Sized, R: RangeBounds >( - data: &'s T, + data: &T, range:R -) -> HexDump<'s, T, R> { +) -> HexDump { HexDump(data, range) } @@ -48,6 +47,7 @@ impl<'s, T: Scannable + ?Sized, R: RangeBounds> Display for HexDump<'s, T // if there is nothing to print then just return... // this also prevents the ilog below from crashing :) if end == 0 || start > end { + write!(f,""); return Ok(()) } @@ -56,6 +56,10 @@ impl<'s, T: Scannable + ?Sized, R: RangeBounds> Display for HexDump<'s, T for (mut addr, chunk) in ChunkIter::new(self.0, start) { for chunk in chunk.chunks(16) { + if addr >= end { return Ok(()) } + + let chunk = &chunk[..(end - addr).min(chunk.len())]; + //╶───╴Column╶────────────────────────────────╴ write!(f, "{:0digits$X}{SEP}", addr, digits = digits)?; @@ -85,9 +89,6 @@ impl<'s, T: Scannable + ?Sized, R: RangeBounds> Display for HexDump<'s, T } } - let mut last_addr = 0usize; - let fchunk = self.0.chunk_at(0); - Ok(()) } }