xkb: XkbSendIndicatorMap(): little simplification
A bit simplification in code flow. The extra length check (did we write as much as intended?) isn't necessary, since the buffer size is computed by the very same data before this function is called. Hint: the size computation must be done before calling this one, because the reply might be encapsulated in another one (xkbGetKbdByName). Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
9c5ae33f0d
commit
d9d03c6241
62
xkb/xkb.c
62
xkb/xkb.c
|
@ -3174,49 +3174,37 @@ static int
|
|||
XkbSendIndicatorMap(ClientPtr client,
|
||||
XkbIndicatorPtr indicators, xkbGetIndicatorMapReply rep)
|
||||
{
|
||||
int length;
|
||||
CARD8 *map;
|
||||
int length = rep.length * 4;
|
||||
|
||||
CARD8 *map = calloc(1, length);
|
||||
if (!map)
|
||||
return BadAlloc;
|
||||
|
||||
register int i;
|
||||
register unsigned bit;
|
||||
|
||||
if (rep.length > 0) {
|
||||
CARD8 *to;
|
||||
xkbIndicatorMapWireDesc *wire = (xkbIndicatorMapWireDesc *) map;
|
||||
|
||||
to = map = xallocarray(rep.length, 4);
|
||||
if (map) {
|
||||
xkbIndicatorMapWireDesc *wire = (xkbIndicatorMapWireDesc *) to;
|
||||
|
||||
length = rep.length * 4;
|
||||
|
||||
for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) {
|
||||
if (rep.which & bit) {
|
||||
wire->flags = indicators->maps[i].flags;
|
||||
wire->whichGroups = indicators->maps[i].which_groups;
|
||||
wire->groups = indicators->maps[i].groups;
|
||||
wire->whichMods = indicators->maps[i].which_mods;
|
||||
wire->mods = indicators->maps[i].mods.mask;
|
||||
wire->realMods = indicators->maps[i].mods.real_mods;
|
||||
wire->virtualMods = indicators->maps[i].mods.vmods;
|
||||
wire->ctrls = indicators->maps[i].ctrls;
|
||||
if (client->swapped) {
|
||||
swaps(&wire->virtualMods);
|
||||
swapl(&wire->ctrls);
|
||||
}
|
||||
wire++;
|
||||
for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) {
|
||||
if (rep.which & bit) {
|
||||
wire->flags = indicators->maps[i].flags;
|
||||
wire->whichGroups = indicators->maps[i].which_groups;
|
||||
wire->groups = indicators->maps[i].groups;
|
||||
wire->whichMods = indicators->maps[i].which_mods;
|
||||
wire->mods = indicators->maps[i].mods.mask;
|
||||
wire->realMods = indicators->maps[i].mods.real_mods;
|
||||
wire->virtualMods = indicators->maps[i].mods.vmods;
|
||||
wire->ctrls = indicators->maps[i].ctrls;
|
||||
if (client->swapped) {
|
||||
swaps(&wire->virtualMods);
|
||||
swapl(&wire->ctrls);
|
||||
}
|
||||
}
|
||||
to = (CARD8 *) wire;
|
||||
if ((to - map) != length) {
|
||||
client->errorValue = _XkbErrCode2(0xff, length);
|
||||
free(map);
|
||||
return BadLength;
|
||||
wire++;
|
||||
}
|
||||
}
|
||||
else
|
||||
return BadAlloc;
|
||||
}
|
||||
else
|
||||
map = NULL;
|
||||
|
||||
if (client->swapped) {
|
||||
swaps(&rep.sequenceNumber);
|
||||
swapl(&rep.length);
|
||||
|
@ -3224,10 +3212,8 @@ XkbSendIndicatorMap(ClientPtr client,
|
|||
swapl(&rep.realIndicators);
|
||||
}
|
||||
WriteToClient(client, sizeof(xkbGetIndicatorMapReply), &rep);
|
||||
if (map) {
|
||||
WriteToClient(client, length, map);
|
||||
free((char *) map);
|
||||
}
|
||||
WriteToClient(client, length, map);
|
||||
free(map);
|
||||
return Success;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue