Commit 7dca986e3f11dea64d7859c1f7c2d87bdd70d6be

Ran Benita 2012-09-21T14:55:46

state, map: check XkbKey != NULL where missing Signed-off-by: Ran Benita <ran234@gmail.com>

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;