state, map: check XkbKey != NULL where missing 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
diff --git a/src/map.c b/src/map.c
index 06e7fe6..6a533e7 100644
--- a/src/map.c
+++ b/src/map.c
@@ -219,6 +219,7 @@ XKB_EXPORT xkb_layout_index_t
xkb_keymap_num_layouts_for_key(struct xkb_keymap *keymap, xkb_keycode_t kc)
{
const struct xkb_key *key = XkbKey(keymap, kc);
+
if (!key)
return 0;
@@ -233,6 +234,7 @@ xkb_keymap_num_levels_for_key(struct xkb_keymap *keymap, xkb_keycode_t kc,
xkb_layout_index_t layout)
{
const struct xkb_key *key = XkbKey(keymap, kc);
+
if (!key)
return 0;
@@ -302,6 +304,8 @@ xkb_keymap_key_get_syms_by_level(struct xkb_keymap *keymap,
const struct xkb_key *key = XkbKey(keymap, kc);
int num_syms;
+ if (!key)
+ goto err;
if (layout >= key->num_groups)
goto err;
if (level >= XkbKeyGroupWidth(keymap, key, layout))
@@ -326,6 +330,7 @@ XKB_EXPORT int
xkb_keymap_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t kc)
{
const struct xkb_key *key = XkbKey(keymap, kc);
+
if (!key)
return 0;
diff --git a/src/state.c b/src/state.c
index 1b0a213..58f74f1 100644
--- a/src/state.c
+++ b/src/state.c
@@ -149,11 +149,11 @@ xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t kc,
XKB_EXPORT xkb_layout_index_t
xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t kc)
{
- const struct xkb_key *key = XkbKey(state->keymap, kc);
xkb_layout_index_t ret =
xkb_state_serialize_layout(state, XKB_STATE_EFFECTIVE);
+ const struct xkb_key *key = XkbKey(state->keymap, kc);
- if (key->num_groups == 0)
+ if (!key || key->num_groups == 0)
return XKB_LAYOUT_INVALID;
if (ret < key->num_groups)
@@ -631,6 +631,7 @@ xkb_state_update_key(struct xkb_state *state, xkb_keycode_t kc,
xkb_mod_index_t i;
xkb_mod_mask_t bit;
const struct xkb_key *key = XkbKey(state->keymap, kc);
+
if (!key)
return;
@@ -713,6 +714,7 @@ xkb_state_key_get_syms(struct xkb_state *state, xkb_keycode_t kc,
xkb_layout_index_t layout;
xkb_level_index_t level;
const struct xkb_key *key = XkbKey(state->keymap, kc);
+
if (!key)
return -1;
@@ -1010,6 +1012,7 @@ xkb_state_mod_index_is_consumed(struct xkb_state *state, xkb_keycode_t kc,
xkb_mod_index_t idx)
{
const struct xkb_key *key = XkbKey(state->keymap, kc);
+
if (!key)
return 0;
@@ -1029,6 +1032,7 @@ xkb_state_mod_mask_remove_consumed(struct xkb_state *state, xkb_keycode_t kc,
xkb_mod_mask_t mask)
{
const struct xkb_key *key = XkbKey(state->keymap, kc);
+
if (!key)
return 0;