diff --git a/xkb/xkb.c b/xkb/xkb.c index 924f83ea5..13cdbbeda 100644 --- a/xkb/xkb.c +++ b/xkb/xkb.c @@ -6382,7 +6382,6 @@ ProcXkbGetDeviceInfo(ClientPtr client) unsigned length, nameLen; CARD16 ledClass, ledID; unsigned wanted; - char *str; REQUEST(xkbGetDeviceInfoReq); REQUEST_SIZE_MATCH(xkbGetDeviceInfoReq); @@ -6484,23 +6483,25 @@ ProcXkbGetDeviceInfo(ClientPtr client) } WriteToClient(client, SIZEOF(xkbGetDeviceInfoReply), &rep); - str = malloc(nameLen); - if (!str) + int sz = nameLen + rep.nBtnsRtrn * sizeof(xkbActionWireDesc); + char *buf = calloc(1, sz); + if (!buf) return BadAlloc; - XkbWriteCountedString(str, dev->name, client->swapped); - WriteToClient(client, nameLen, str); - free(str); - length -= nameLen; + char *walk = buf; + + XkbWriteCountedString(walk, dev->name, client->swapped); + walk += nameLen; if (rep.nBtnsRtrn > 0) { - int sz; - xkbActionWireDesc *awire; - - sz = rep.nBtnsRtrn * SIZEOF(xkbActionWireDesc); - awire = (xkbActionWireDesc *) &dev->button->xkb_acts[rep.firstBtnRtrn]; - WriteToClient(client, sz, awire); - length -= sz; + memcpy(walk, + &dev->button->xkb_acts[rep.firstBtnRtrn], + sizeof(xkbActionWireDesc)*rep.nBtnsRtrn); + walk += sizeof(xkbActionWireDesc)*rep.nBtnsRtrn; } + + WriteToClient(client, sz, buf); + length -= sz; + if (nDeviceLedFBs > 0) { status = SendDeviceLedFBs(dev, ledClass, ledID, length, client); if (status != Success)