From 82491d5fd101393ef77122e449f23e30343f3d9f Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Thu, 30 Aug 2012 12:14:29 +0300 Subject: [PATCH] map, state: check for KeycodeInRange only in API functions Signed-off-by: Ran Benita --- src/map.c | 21 ++++++++------------- src/state.c | 17 +++++++---------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/map.c b/src/map.c index 532d00d..d133ae1 100644 --- a/src/map.c +++ b/src/map.c @@ -205,9 +205,10 @@ xkb_map_group_get_index(struct xkb_keymap *keymap, const char *name) XKB_EXPORT xkb_group_index_t xkb_key_num_groups(struct xkb_keymap *keymap, xkb_keycode_t kc) { - if (XkbKeycodeInRange(keymap, kc)) - return XkbKey(keymap, kc)->num_groups; - return 0; + if (!XkbKeycodeInRange(keymap, kc)) + return 0; + + return XkbKey(keymap, kc)->num_groups; } /** @@ -290,12 +291,8 @@ xkb_key_get_level(struct xkb_state *state, xkb_keycode_t kc, { struct xkb_kt_map_entry *entry; - if (!XkbKeycodeInRange(xkb_state_get_map(state), kc)) - return XKB_LEVEL_INVALID; - - entry = get_entry_for_key_state(state, kc); - /* If we don't find an explicit match the default is 0. */ + entry = get_entry_for_key_state(state, kc); if (!entry) return 0; @@ -310,12 +307,9 @@ xkb_group_index_t xkb_key_get_group(struct xkb_state *state, xkb_keycode_t kc) { struct xkb_keymap *keymap = xkb_state_get_map(state); + struct xkb_key *key; xkb_group_index_t ret = xkb_state_serialize_group(state, XKB_STATE_EFFECTIVE); - struct xkb_key *key; - - if (!XkbKeycodeInRange(keymap, kc)) - return XKB_GROUP_INVALID; key = XkbKey(keymap, kc); if (key->num_groups == 0) @@ -384,7 +378,7 @@ xkb_key_get_syms(struct xkb_state *state, xkb_keycode_t kc, xkb_group_index_t group; xkb_level_index_t level; - if (!state || !XkbKeycodeInRange(keymap, kc)) + if (!XkbKeycodeInRange(keymap, kc)) return -1; key = XkbKey(keymap, kc); @@ -412,6 +406,7 @@ xkb_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t kc) { if (!XkbKeycodeInRange(keymap, kc)) return 0; + return XkbKey(keymap, kc)->repeats; } diff --git a/src/state.c b/src/state.c index dbb05be..2532f87 100644 --- a/src/state.c +++ b/src/state.c @@ -113,12 +113,11 @@ xkb_key_get_action(struct xkb_state *state, xkb_keycode_t kc) { xkb_group_index_t group; xkb_level_index_t level; - struct xkb_key *key = NULL; + struct xkb_key *key; - if (XkbKeycodeInRange(state->keymap, kc)) - key = XkbKey(state->keymap, kc); + key = XkbKey(state->keymap, kc); - if (!key || !key->actions) + if (!key->actions) return &fake; group = xkb_key_get_group(state, kc); @@ -487,9 +486,6 @@ xkb_state_new(struct xkb_keymap *keymap) { struct xkb_state *ret; - if (!keymap) - return NULL; - ret = calloc(sizeof(*ret), 1); if (!ret) return NULL; @@ -510,9 +506,7 @@ xkb_state_ref(struct xkb_state *state) XKB_EXPORT void xkb_state_unref(struct xkb_state *state) { - state->refcnt--; - assert(state->refcnt >= 0); - if (state->refcnt > 0) + if (--state->refcnt > 0) return; xkb_map_unref(state->keymap); @@ -600,6 +594,9 @@ xkb_state_update_key(struct xkb_state *state, xkb_keycode_t kc, xkb_mod_index_t i; xkb_mod_mask_t bit; + if (!XkbKeycodeInRange(state->keymap, kc)) + return; + state->set_mods = 0; state->clear_mods = 0; -- 2.7.4