From: Ran Benita Date: Wed, 15 Aug 2012 19:07:37 +0000 (+0300) Subject: vmod: remove support for resolving integer to virtual modifier X-Git-Tag: xkbcommon-0.2.0~243 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f410622b4bcbe79d0c51e98e058a3bffee0b7a66;p=platform%2Fupstream%2Flibxkbcommon.git vmod: remove support for resolving integer to virtual modifier This is only relevant to the virtualModifier= statement in interpret statements in xkb_compat. The current code allows to write e.g. virtualModifier = 4 to get the virtual modifier whose index happens to be 4 (possibly declared in other files or sections, i.e. xkb_types). Doing this is undeterministic, will break without notice, and not used anywhere. Don't allow it. Signed-off-by: Ran Benita --- diff --git a/src/utils.h b/src/utils.h index 0f7a384..3fda939 100644 --- a/src/utils.h +++ b/src/utils.h @@ -44,6 +44,14 @@ streq(const char *s1, const char *s2) } static inline bool +streq_not_null(const char *s1, const char *s2) +{ + if (!s1 || !s2) + return false; + return streq(s1, s2); +} + +static inline bool istreq(const char *s1, const char *s2) { return strcasecmp(s1, s2) == 0; diff --git a/src/xkbcomp/vmod.c b/src/xkbcomp/vmod.c index 7ce943c..de5647d 100644 --- a/src/xkbcomp/vmod.c +++ b/src/xkbcomp/vmod.c @@ -173,32 +173,29 @@ bool ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap, xkb_mod_index_t *ndx_rtrn, VModInfo *info) { - int val; - - if (def->op == EXPR_IDENT) { - xkb_mod_index_t i; - xkb_mod_mask_t bit; - const char *name = xkb_atom_text(keymap->ctx, def->value.str); - - for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) { - if ((info->available & bit) && keymap->vmod_names[i] && - streq(keymap->vmod_names[i], name)) { - *ndx_rtrn = i; - return true; - } - } - } - - if (!ExprResolveInteger(keymap->ctx, def, &val)) - return false; + xkb_mod_index_t i; + const char *name; - if (val < 0 || val >= XkbNumVirtualMods) { + if (def->op != EXPR_IDENT) { log_err(keymap->ctx, - "Illegal virtual modifier %d (must be 0..%d inclusive)\n", - val, XkbNumVirtualMods - 1); + "Cannot resolve virtual modifier: " + "found %s where a virtual modifier name was expected\n", + expr_op_type_to_string(def->op)); return false; } - *ndx_rtrn = (xkb_mod_index_t) val; - return true; + name = xkb_atom_text(keymap->ctx, def->value.str); + + for (i = 0; i < XkbNumVirtualMods; i++) { + if ((info->available & (1 << i)) && + streq_not_null(keymap->vmod_names[i], name)) { + *ndx_rtrn = i; + return true; + } + } + + log_err(keymap->ctx, + "Cannot resolve virtual modifier: " + "\"%s\" was not previously declared\n", name); + return false; }