From a82d73122d95f3b01e3dfad86f0f34e7584ffe75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 14 Nov 2021 00:20:30 +0100 Subject: [PATCH] pkstrings: prevent addition from overflowing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- pkstrings/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkstrings/src/lib.rs b/pkstrings/src/lib.rs index 06b023c..059694e 100644 --- a/pkstrings/src/lib.rs +++ b/pkstrings/src/lib.rs @@ -57,14 +57,14 @@ const fn strtohex(chr: &char) -> Option { const fn hextostr(hex: u8) -> Option { Some(match hex { - cap @ 0x80..=0x99 => (('A' as u8) + cap - 0x80) as char, + cap @ 0x80..=0x99 => (('A' as u8) + (cap - 0x80)) as char, 0x9a => '(', 0x9b => ')', 0x9c => ':', 0x9d => ';', 0x9e => '[', 0x9f => ']', - low @ 0xa0..=0xb9 => (('a' as u8) + low - 0xa0) as char, + low @ 0xa0..=0xb9 => (('a' as u8) + (low - 0xa0)) as char, 0xe0 => '\'', 0xe3 => '-', 0xe6 => '?', @@ -79,7 +79,7 @@ const fn hextostr(hex: u8) -> Option { 0xf3 => '/', 0xf4 => ',', 0xf5 => '♀', - num @ 0xf6..=0xff => (('0' as u8) + num - 0xf6) as char, + num @ 0xf6..=0xff => (('0' as u8) + (num - 0xf6)) as char, 0x7f => ' ', 0x50 => '@', _ => return None,