Skip to content

Commit 4fe30e3

Browse files
committed
Fix overflow
1 parent 2539ccb commit 4fe30e3

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/keytables.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ const char char_or_func[] = // c = character key, f = function key, _ = blank/e
4040

4141
inline bool is_char_key(unsigned int code)
4242
{
43-
assert(code < sizeof(char_or_func));
43+
assert(code < sizeof(char_or_func)-1);
4444
return (char_or_func[code] == 'c');
4545
}
4646

4747
inline bool is_func_key(unsigned int code)
4848
{
49-
assert(code < sizeof(char_or_func));
49+
assert(code < sizeof(char_or_func)-1);
5050
return (char_or_func[code] == 'f');
5151
}
5252

5353
inline bool is_used_key(unsigned int code)
5454
{
55-
assert(code < sizeof(char_or_func));
55+
assert(code < sizeof(char_or_func)-1);
5656
return (char_or_func[code] != '_');
5757
}
5858

src/logkeys.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ void determine_system_keymap()
189189
std::stringstream ss, dump(execute(COMMAND_STR_DUMPKEYS)); // see example output after i.e. `loadkeys slovene`
190190
std::string line;
191191

192-
unsigned int i = 0; // keycode
192+
unsigned int i = -1; // keycode
193193
int index;
194194
int utf8code; // utf-8 code of keysym answering keycode i
195195

@@ -205,7 +205,7 @@ void determine_system_keymap()
205205
index = line.find("U+", index);
206206
}
207207

208-
if (++i >= sizeof(char_or_func)) break; // only ever map keycodes up to 128 (currently N_KEYS_DEFINED are used)
208+
if (++i >= sizeof(char_or_func)-1) break; // only ever map keycodes up to 128 (currently N_KEYS_DEFINED are used)
209209
if (!is_char_key(i)) continue; // only map character keys of keyboard
210210

211211
assert(line.size() > 0);

0 commit comments

Comments
 (0)