x11: don't trust keycode before testing its range The assert is not very useful access the key just before. Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
diff --git a/src/x11/keymap.c b/src/x11/keymap.c
index 4c6b29c..57f2412 100644
--- a/src/x11/keymap.c
+++ b/src/x11/keymap.c
@@ -536,11 +536,13 @@ get_explicits(struct xkb_keymap *keymap, xcb_connection_t *conn,
for (int i = 0; i < length; i++) {
xcb_xkb_set_explicit_t *wire = iter.data;
- struct xkb_key *key = &keymap->keys[wire->keycode];
+ struct xkb_key *key;
FAIL_UNLESS(wire->keycode >= keymap->min_key_code &&
wire->keycode <= keymap->max_key_code);
+ key = &keymap->keys[wire->keycode];
+
if ((wire->explicit & XCB_XKB_EXPLICIT_KEY_TYPE_1) &&
key->num_groups > 0)
key->groups[0].explicit_type = true;
@@ -579,11 +581,12 @@ get_modmaps(struct xkb_keymap *keymap, xcb_connection_t *conn,
for (int i = 0; i < length; i++) {
xcb_xkb_key_mod_map_t *wire = iter.data;
- struct xkb_key *key = &keymap->keys[wire->keycode];
+ struct xkb_key *key;
FAIL_UNLESS(wire->keycode >= keymap->min_key_code &&
wire->keycode <= keymap->max_key_code);
+ key = &keymap->keys[wire->keycode];
key->modmap = wire->mods;
xcb_xkb_key_mod_map_next(&iter);
@@ -605,11 +608,12 @@ get_vmodmaps(struct xkb_keymap *keymap, xcb_connection_t *conn,
for (int i = 0; i < length; i++) {
xcb_xkb_key_v_mod_map_t *wire = iter.data;
- struct xkb_key *key = &keymap->keys[wire->keycode];
+ struct xkb_key *key;
FAIL_UNLESS(wire->keycode >= keymap->min_key_code &&
wire->keycode <= keymap->max_key_code);
+ key = &keymap->keys[wire->keycode];
key->vmodmap = translate_mods(0, wire->vmods, 0);
xcb_xkb_key_v_mod_map_next(&iter);