fix panic if len is zero
This commit is contained in:
@@ -7,11 +7,11 @@ const SEP: &str = " | ";
|
||||
pub struct HexDump<'s, T: Scannable + ?Sized, R: RangeBounds<usize>>(pub &'s T, pub R);
|
||||
|
||||
pub fn hex<
|
||||
's,
|
||||
T: Scannable + ?Sized,
|
||||
's,
|
||||
T: Scannable + ?Sized,
|
||||
R: RangeBounds<usize>
|
||||
>(
|
||||
data: &'s T,
|
||||
data: &'s T,
|
||||
range:R
|
||||
) -> HexDump<'s, T, R> {
|
||||
HexDump(data, range)
|
||||
@@ -45,6 +45,12 @@ impl<'s, T: Scannable + ?Sized, R: RangeBounds<usize>> Display for HexDump<'s, T
|
||||
(start, end)
|
||||
};
|
||||
|
||||
// if there is nothing to print then just return...
|
||||
// this also prevents the ilog below from crashing :)
|
||||
if end == 0 || start > end {
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
// the number of digits the address column should have
|
||||
let digits = (end.ilog(16) as usize + 1).max(4);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user