From 4fe30e3c6329e3b23fcfaa181119b9796219b487 Mon Sep 17 00:00:00 2001 From: Zachary Vance Date: Wed, 3 Aug 2022 16:41:18 -0400 Subject: [PATCH] Fix overflow --- src/keytables.cc | 6 +++--- src/logkeys.cc | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/keytables.cc b/src/keytables.cc index 2ec5dad..94b139b 100644 --- a/src/keytables.cc +++ b/src/keytables.cc @@ -40,19 +40,19 @@ const char char_or_func[] = // c = character key, f = function key, _ = blank/e inline bool is_char_key(unsigned int code) { - assert(code < sizeof(char_or_func)); + assert(code < sizeof(char_or_func)-1); return (char_or_func[code] == 'c'); } inline bool is_func_key(unsigned int code) { - assert(code < sizeof(char_or_func)); + assert(code < sizeof(char_or_func)-1); return (char_or_func[code] == 'f'); } inline bool is_used_key(unsigned int code) { - assert(code < sizeof(char_or_func)); + assert(code < sizeof(char_or_func)-1); return (char_or_func[code] != '_'); } diff --git a/src/logkeys.cc b/src/logkeys.cc index 5da3cff..63c1a21 100644 --- a/src/logkeys.cc +++ b/src/logkeys.cc @@ -189,7 +189,7 @@ void determine_system_keymap() std::stringstream ss, dump(execute(COMMAND_STR_DUMPKEYS)); // see example output after i.e. `loadkeys slovene` std::string line; - unsigned int i = 0; // keycode + unsigned int i = -1; // keycode int index; int utf8code; // utf-8 code of keysym answering keycode i @@ -205,7 +205,7 @@ void determine_system_keymap() index = line.find("U+", index); } - if (++i >= sizeof(char_or_func)) break; // only ever map keycodes up to 128 (currently N_KEYS_DEFINED are used) + if (++i >= sizeof(char_or_func)-1) break; // only ever map keycodes up to 128 (currently N_KEYS_DEFINED are used) if (!is_char_key(i)) continue; // only map character keys of keyboard assert(line.size() > 0);