summaryrefslogtreecommitdiff
path: root/console-client/xkb
diff options
context:
space:
mode:
authorDiego Nieto Cid <dnietoc@gmail.com>2010-07-25 17:15:01 -0300
committerDiego Nieto Cid <dnietoc@gmail.com>2011-04-08 14:36:17 -0300
commit1947d8a1a99974ff008b98a46923ad9ccef28284 (patch)
tree0074f912c3103d8f754eadbcc477a1dc9df89e76 /console-client/xkb
parenteffb6217301ea3c63341fc8998f462e0ecacb11a (diff)
Avoid hashing garbage for short keynames.
Diffstat (limited to 'console-client/xkb')
-rw-r--r--console-client/xkb/xkbdata.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/console-client/xkb/xkbdata.c b/console-client/xkb/xkbdata.c
index bd23c468..382881b8 100644
--- a/console-client/xkb/xkbdata.c
+++ b/console-client/xkb/xkbdata.c
@@ -50,6 +50,14 @@ keyname_init ()
/* XXX: error. */
}
+static inline int
+keyname_hash(char *keyname)
+{
+ char tmp[4] = { 0 };
+ strncpy(tmp, keyname, sizeof tmp);
+ return tmp[0] + (tmp[1] << 8) + (tmp[2] << 16) + (tmp[3] << 24);
+}
+
/* Assign the name KEYNAME to the keycode KEYCODE. */
error_t
keyname_add (char *keyname, int keycode)
@@ -74,7 +82,7 @@ keyname_add (char *keyname, int keycode)
kn->keycode = keycode;
kn->rmods = 0;
- kn_int = keyname[0] + (keyname[1] << 8) + (keyname[2] << 16) + (keyname[3] << 24);
+ kn_int = keyname_hash(keyname);
debug_printf ("add : %d\n", kn_mapping.locp_offset);
hurd_ihash_add (&kn_mapping, kn_int, kn);
@@ -98,7 +106,7 @@ keyname_find (char *keyname)
/* XXX: Abort? */
return 0;
}
- kn_int = keyname[0] + (keyname[1] << 8) + (keyname[2] << 16) + (keyname[3] << 24);
+ kn_int = keyname_hash(keyname);
kn = hurd_ihash_find (&kn_mapping, kn_int);
if (kn)