From 4d7902036881a5d93286c72fffc3a7b10e16644d Mon Sep 17 00:00:00 2001 From: matcap Date: Sun, 23 Jul 2023 20:00:01 +0200 Subject: [PATCH] check for underflow when calculating maximum address prefix --- src/pretty_hex.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pretty_hex.rs b/src/pretty_hex.rs index fc284c2..28a2db0 100644 --- a/src/pretty_hex.rs +++ b/src/pretty_hex.rs @@ -151,7 +151,11 @@ where let lines_len = lines.len(); - let max_address = source.len() - cfg.width + cfg.display_offset; + let max_address = if source.len() <= cfg.width { + source.len() + cfg.display_offset + } else { + source.len() - cfg.width + cfg.display_offset + }; let write_address = get_address_writer(max_address); for (i, row) in lines.enumerate() {