[PATCH] XStringToKeysym: Cope with 0x1234cafe-style input

Daniel Stone daniel at fooishbar.org
Fri Jul 9 12:07:00 PDT 2010


If we get input in the style of 0xdeadbeef, just return that exact
keysym.  Introduces a dependency on strtoul, which I'm told is OK on all
the systems we care about.

Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
 configure.ac    |    2 ++
 src/StrKeysym.c |   12 ++++++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/configure.ac b/configure.ac
index 577f581..9c4d1f9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -310,6 +310,8 @@ AC_SUBST(XTHREAD_CFLAGS)
 
 AC_CHECK_FUNC(poll, [AC_DEFINE(USE_POLL, 1, [poll() function is available])], )
 
+AC_CHECK_HEADERS([limits.h])
+
 #
 # Find keysymdef.h
 #
diff --git a/src/StrKeysym.c b/src/StrKeysym.c
index 4bed94b..ac9c3ea 100644
--- a/src/StrKeysym.c
+++ b/src/StrKeysym.c
@@ -27,6 +27,9 @@ in this Software without prior written authorization from The Open Group.
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
 #include "Xlibint.h"
 #include <X11/Xresource.h>
 #include <X11/keysymdef.h>
@@ -153,6 +156,15 @@ XStringToKeysym(_Xconst char *s)
         return val | 0x01000000;
     }
 
+    if (strlen(s) > 2 && s[0] == '0' && s[1] == 'x') {
+        char *tmp = NULL;
+        val = strtoul(s, &tmp, 16);
+        if (val == ULONG_MAX || (tmp && *tmp != '\0'))
+            return NoSymbol;
+        else
+            return val;
+    }
+
     /* Stupid inconsistency between the headers and XKeysymDB: the former has
      * no separating underscore, while some XF86* syms in the latter did.
      * As a last ditch effort, try without. */
-- 
1.7.1



More information about the xorg-devel mailing list