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>
master
Daniel Stone 2012-02-20 18:07:29 +00:00
parent 1ab058bbb3
commit 90f04e042b
2 changed files with 12 additions and 19 deletions

View File

@ -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

View File

@ -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))
{