From a1cb362dda3b5988bcd2b8bbf0c3b33fde6e7e9b Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 21 Mar 2022 14:59:20 +0100 Subject: [PATCH] Fix subtract with overflow in Hz->kHz formatter When supplying a short input value without a unit. --- src/formatters.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/formatters.rs b/src/formatters.rs index 0db58217..f2b51322 100644 --- a/src/formatters.rs +++ b/src/formatters.rs @@ -91,7 +91,7 @@ pub fn from_f32_hz_then_khz() -> Arc Option + Send + Sync> .trim_end_matches(&[' ', 'k', 'K', 'h', 'H', 'z', 'Z']) .parse() .ok(); - match string.get(string.len() - 3..) { + match string.get(string.len().saturating_sub(3)..) { Some(unit) if unit.eq_ignore_ascii_case("khz") => cleaned_string.map(|x| x * 1000.0), // Even if there's no unit at all, just assume the input is in Hertz _ => cleaned_string,