From 1028aad99c94201e146115c42aff042dc4672b0e Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 16 Jul 2024 11:04:24 +0200 Subject: [PATCH] (1623) 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 --- xkb/xkb.c | 62 +++++++++++++++++++++---------------------------------- 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/xkb/xkb.c b/xkb/xkb.c index 39935f3b6..cd5a22882 100644 --- a/xkb/xkb.c +++ b/xkb/xkb.c @@ -3175,49 +3175,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 = calloc(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); @@ -3225,10 +3213,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; }