<<< Date Index >>>     <<< Thread Index >>>

[PATCH] allow octal codes with more than three digits



 keymap.c |  18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)


# HG changeset patch
# User Michael Elkins <me@xxxxxxxx>
# Date 1271959872 25200
# Branch HEAD
# Node ID 611ac36d7c18e1fb92723b57b72938f8d9cc694c
# Parent  6ebdfd09abc138766d06b2af0311f5667fb9795c
allow octal codes with more than three digits

diff --git a/keymap.c b/keymap.c
--- a/keymap.c
+++ b/keymap.c
@@ -134,14 +134,16 @@
  */
 static int parse_keycode (const char *s)
 {
-  if (isdigit ((unsigned char) s[1]) &&
-      isdigit ((unsigned char) s[2]) &&
-      isdigit ((unsigned char) s[3]) &&
-      s[4] == '>')
-  {
-    return (s[3] - '0') + (s[2] - '0') * 8 + (s[1] - '0') * 64;
-  }
-  return -1;
+    const char *endChar;
+    long int result = strtol(s+1, &endChar, 8);
+    /* allow trailing whitespace, eg.  < 1001 > */
+    while (ISSPACE(*endChar))
+       ++endChar;
+    /* negative keycodes don't make sense, also detect overflow */
+    if (*endChar != '>' || result < 0 || result == LONG_MAX) {
+       return -1;
+    }
+    return result;
 }
 
 static int parsekeys (char *str, keycode_t *d, int max)