xkb: XkbSendCompatMap(): little cleanup and simplification
Make it a bit simpler and easier to read. calloc() and WriteToClient() can handle zero lengths very well. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
d1555edcc2
commit
f3176bae97
81
xkb/xkb.c
81
xkb/xkb.c
|
@ -2806,52 +2806,45 @@ static int
|
||||||
XkbSendCompatMap(ClientPtr client,
|
XkbSendCompatMap(ClientPtr client,
|
||||||
XkbCompatMapPtr compat, xkbGetCompatMapReply rep)
|
XkbCompatMapPtr compat, xkbGetCompatMapReply rep)
|
||||||
{
|
{
|
||||||
char *data;
|
int sz = rep.length * sizeof(CARD32);
|
||||||
int size;
|
char *buf = calloc(1, sz);
|
||||||
|
if (sz && (!buf))
|
||||||
|
return BadAlloc;
|
||||||
|
|
||||||
if (rep.length > 0) {
|
if (sz) {
|
||||||
data = calloc(rep.length, 4);
|
register unsigned i, bit;
|
||||||
if (data) {
|
xkbModsWireDesc *grp;
|
||||||
register unsigned i, bit;
|
XkbSymInterpretPtr sym = &compat->sym_interpret[rep.firstSI];
|
||||||
xkbModsWireDesc *grp;
|
xkbSymInterpretWireDesc *wire = (xkbSymInterpretWireDesc *) buf;
|
||||||
XkbSymInterpretPtr sym = &compat->sym_interpret[rep.firstSI];
|
|
||||||
xkbSymInterpretWireDesc *wire = (xkbSymInterpretWireDesc *) data;
|
|
||||||
|
|
||||||
size = rep.length * 4;
|
for (i = 0; i < rep.nSI; i++, sym++, wire++) {
|
||||||
|
wire->sym = sym->sym;
|
||||||
for (i = 0; i < rep.nSI; i++, sym++, wire++) {
|
wire->mods = sym->mods;
|
||||||
wire->sym = sym->sym;
|
wire->match = sym->match;
|
||||||
wire->mods = sym->mods;
|
wire->virtualMod = sym->virtual_mod;
|
||||||
wire->match = sym->match;
|
wire->flags = sym->flags;
|
||||||
wire->virtualMod = sym->virtual_mod;
|
memcpy((char *) &wire->act, (char *) &sym->act,
|
||||||
wire->flags = sym->flags;
|
sz_xkbActionWireDesc);
|
||||||
memcpy((char *) &wire->act, (char *) &sym->act,
|
if (client->swapped) {
|
||||||
sz_xkbActionWireDesc);
|
swapl(&wire->sym);
|
||||||
if (client->swapped) {
|
|
||||||
swapl(&wire->sym);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (rep.groups) {
|
|
||||||
grp = (xkbModsWireDesc *) wire;
|
|
||||||
for (i = 0, bit = 1; i < XkbNumKbdGroups; i++, bit <<= 1) {
|
|
||||||
if (rep.groups & bit) {
|
|
||||||
grp->mask = compat->groups[i].mask;
|
|
||||||
grp->realMods = compat->groups[i].real_mods;
|
|
||||||
grp->virtualMods = compat->groups[i].vmods;
|
|
||||||
if (client->swapped) {
|
|
||||||
swaps(&grp->virtualMods);
|
|
||||||
}
|
|
||||||
grp++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wire = (xkbSymInterpretWireDesc *) grp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
if (rep.groups) {
|
||||||
return BadAlloc;
|
grp = (xkbModsWireDesc *) wire;
|
||||||
|
for (i = 0, bit = 1; i < XkbNumKbdGroups; i++, bit <<= 1) {
|
||||||
|
if (rep.groups & bit) {
|
||||||
|
grp->mask = compat->groups[i].mask;
|
||||||
|
grp->realMods = compat->groups[i].real_mods;
|
||||||
|
grp->virtualMods = compat->groups[i].vmods;
|
||||||
|
if (client->swapped) {
|
||||||
|
swaps(&grp->virtualMods);
|
||||||
|
}
|
||||||
|
grp++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wire = (xkbSymInterpretWireDesc *) grp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
data = NULL;
|
|
||||||
|
|
||||||
if (client->swapped) {
|
if (client->swapped) {
|
||||||
swaps(&rep.sequenceNumber);
|
swaps(&rep.sequenceNumber);
|
||||||
|
@ -2862,10 +2855,8 @@ XkbSendCompatMap(ClientPtr client,
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteToClient(client, sizeof(xkbGetCompatMapReply), &rep);
|
WriteToClient(client, sizeof(xkbGetCompatMapReply), &rep);
|
||||||
if (data) {
|
WriteToClient(client, sz, buf);
|
||||||
WriteToClient(client, size, data);
|
free(buf);
|
||||||
free((char *) data);
|
|
||||||
}
|
|
||||||
return Success;
|
return Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue