Perform bounds checking in ExprResolveLevel Both callers perform the same bounds check, so move it into ExprResolveLevel itself. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c
index 929548a..c0c4c6f 100644
--- a/src/xkbcomp/expr.c
+++ b/src/xkbcomp/expr.c
@@ -673,6 +673,7 @@ int
ExprResolveLevel(ExprDef * expr,
ExprResult * val_rtrn)
{
+ int ret;
static LookupEntry level_names[] = {
{ "level1", 1 },
{ "level2", 2 },
@@ -685,8 +686,17 @@ ExprResolveLevel(ExprDef * expr,
{ NULL, 0 }
};
- return ExprResolveIntegerLookup(expr, val_rtrn, SimpleLookup,
- level_names);
+ ret = ExprResolveIntegerLookup(expr, val_rtrn, SimpleLookup, level_names);
+ if (ret == False)
+ return ret;
+
+ if (val_rtrn->ival < 1 || val_rtrn->ival > XkbMaxShiftLevel) {
+ ERROR("Shift level %d is out of range (1..%d)\n", val_rtrn->ival,
+ XkbMaxShiftLevel);
+ return False;
+ }
+
+ return True;
}
int
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index 57164d2..f516276 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -679,14 +679,6 @@ SetMapEntry(KeyTypeInfo * type,
ACTION("Ignoring malformed level specification\n");
return False;
}
- if ((rtrn.ival < 1) || (rtrn.ival > XkbMaxShiftLevel + 1))
- {
- ERROR("Shift level %d out of range (1..%d) in key type %s\n",
- XkbMaxShiftLevel + 1, rtrn.ival, TypeTxt(type));
- ACTION("Ignoring illegal definition of map[%s]\n",
- MapEntryTxt(xkb, &entry));
- return False;
- }
entry.level = rtrn.ival - 1;
return AddMapEntry(xkb, type, &entry, True, True);
}
@@ -811,15 +803,6 @@ SetLevelName(KeyTypeInfo * type, ExprDef * arrayNdx, ExprDef * value)
return ReportTypeShouldBeArray(type, "level name");
if (!ExprResolveLevel(arrayNdx, &rtrn))
return ReportTypeBadType(type, "level name", "integer");
- if ((rtrn.ival < 1) || (rtrn.ival > XkbMaxShiftLevel + 1))
- {
- ERROR("Level name %d out of range (1..%d) in key type %s\n",
- rtrn.ival,
- XkbMaxShiftLevel + 1,
- XkbcAtomText(type->name));
- ACTION("Ignoring illegal level name definition\n");
- return False;
- }
level = rtrn.ival - 1;
if (!ExprResolveString(value, &rtrn))
{