Fix type of keycode in parser and ast
authorRan Benita <ran234@gmail.com>
Thu, 27 Sep 2012 17:21:26 +0000 (19:21 +0200)
committerRan Benita <ran234@gmail.com>
Thu, 27 Sep 2012 19:12:08 +0000 (21:12 +0200)
For some reason keycodes were listed under mapFlags in the yylval union.
Fix it and some sanity checks.

Signed-off-by: Ran Benita <ran234@gmail.com>
src/xkbcomp/ast-build.c
src/xkbcomp/ast-build.h
src/xkbcomp/ast.h
src/xkbcomp/keycodes.c
src/xkbcomp/parser.y

index dcfbb38..4ce4752 100644 (file)
@@ -137,7 +137,7 @@ ExprCreateBinary(enum expr_op_type op, ExprDef *left, ExprDef *right)
 }
 
 KeycodeDef *
-KeycodeCreate(xkb_atom_t name, unsigned long value)
+KeycodeCreate(xkb_atom_t name, int64_t value)
 {
     KeycodeDef *def;
 
index d433240..b600389 100644 (file)
@@ -41,7 +41,7 @@ ExprDef *
 ExprCreateBinary(enum expr_op_type op, ExprDef *left, ExprDef *right);
 
 KeycodeDef *
-KeycodeCreate(xkb_atom_t name, unsigned long value);
+KeycodeCreate(xkb_atom_t name, int64_t value);
 
 KeyAliasDef *
 KeyAliasCreate(xkb_atom_t alias, xkb_atom_t real);
index 4d8bc83..425e502 100644 (file)
@@ -211,7 +211,7 @@ typedef struct _KeycodeDef {
     ParseCommon common;
     enum merge_mode merge;
     xkb_atom_t name;
-    unsigned long value;
+    int64_t value;
 } KeycodeDef;
 
 typedef struct _KeyAliasDef {
index f134d85..4273ebe 100644 (file)
@@ -461,7 +461,7 @@ HandleIncludeKeycodes(KeyNamesInfo *info, IncludeStmt *stmt)
     return (info->errorCount == 0);
 }
 
-static int
+static bool
 HandleKeycodeDef(KeyNamesInfo *info, KeycodeDef *stmt, enum merge_mode merge)
 {
     if (stmt->merge != MERGE_DEFAULT) {
@@ -471,6 +471,13 @@ HandleKeycodeDef(KeyNamesInfo *info, KeycodeDef *stmt, enum merge_mode merge)
             merge = stmt->merge;
     }
 
+    if (stmt->value < 0 || stmt->value > XKB_KEYCODE_MAX) {
+        log_err(info->ctx,
+                "Illegal keycode %lld: must be between 0..%u; "
+                "Key ignored\n", stmt->value, XKB_KEYCODE_MAX);
+        return false;
+    }
+
     return AddKeyName(info, stmt->value, stmt->name, merge,
                       info->file_id, true);
 }
index 3f0cc53..781a483 100644 (file)
@@ -146,11 +146,12 @@ _xkbcommon_error(struct YYLTYPE *loc, struct parser_param *param, const char *ms
 %type <num>     INTEGER FLOAT
 %type <str>     IDENT STRING
 %type <sval>    KEYNAME
+%type <num>     KeyCode
 %type <ival>    Number Integer Float SignedNumber
 %type <merge>   MergeMode OptMergeMode
 %type <file_type> XkbCompositeType FileType
 %type <uval>    DoodadType
-%type <mapFlags> Flag Flags OptFlags KeyCode
+%type <mapFlags> Flag Flags OptFlags
 %type <str>     MapName OptMapName KeySym
 %type <sval>    FieldSpec Ident Element String
 %type <any>     DeclList Decl