From c4b492b36dd6b3be4b72bbee43319fcfc17dca17 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Fri, 29 Aug 2025 17:37:37 +0200 Subject: [PATCH] xkb: ProcXkbGetDeviceInfo(): use x_rpcbuf_t for reply payload assembly At this point just use it as allocator, so we can use the X_SEND_REPLY_WITH_RPCBUF() macro for final sending. Follow-up commits will change the whole call stack to operate on x_rpcbuf_t directly, so it's also doing the byte-swap for us. Signed-off-by: Enrico Weigelt, metux IT consult --- xkb/xkb.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/xkb/xkb.c b/xkb/xkb.c index 2c5a549d5..bd326523a 100644 --- a/xkb/xkb.c +++ b/xkb/xkb.c @@ -6317,9 +6317,10 @@ ProcXkbGetDeviceInfo(ClientPtr client) } length = rep.length * 4; - if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); + + x_rpcbuf_t rpcbuf = { .swapped = client->swapped, .err_clear = TRUE }; + + if (rpcbuf.swapped) { swaps(&rep.present); swaps(&rep.supported); swaps(&rep.unsupported); @@ -6328,10 +6329,9 @@ ProcXkbGetDeviceInfo(ClientPtr client) swaps(&rep.dfltLedFB); swapl(&rep.devType); } - WriteToClient(client, SIZEOF(xkbGetDeviceInfoReply), &rep); int sz = nameLen + rep.nBtnsRtrn * sizeof(xkbActionWireDesc) + led_len; - char *buf = calloc(1, sz); + char *buf = x_rpcbuf_reserve(&rpcbuf, sz); if (!buf) return BadAlloc; char *walk = buf; @@ -6350,18 +6350,20 @@ ProcXkbGetDeviceInfo(ClientPtr client) if (nDeviceLedFBs > 0) { status = FillDeviceLedFBs(dev, ledClass, ledID, length, walk, client); - if (status != Success) + if (status != Success) { + x_rpcbuf_clear(&rpcbuf); return status; + } } else if (length != 0) { ErrorF("[xkb] Internal Error! BadLength in ProcXkbGetDeviceInfo\n"); ErrorF("[xkb] Wrote %d fewer bytes than expected\n", length); + x_rpcbuf_clear(&rpcbuf); return BadLength; } - WriteToClient(client, sz, buf); - return Success; + return X_SEND_REPLY_WITH_RPCBUF(client, rep, rpcbuf); } static char *