Skip to content

Commit

Permalink
Fix overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
za3k committed Aug 3, 2022
1 parent 2539ccb commit 4fe30e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/keytables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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] != '_');
}

Expand Down
4 changes: 2 additions & 2 deletions src/logkeys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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);
Expand Down

0 comments on commit 4fe30e3

Please sign in to comment.