From 8c90875c3d7d385e00bf271c16e6512ecf54765f Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 28 Aug 2025 17:21:00 +0200 Subject: [PATCH] Xi: ProcXListInputDevices(): use x_rpcbuf_t use x_rpcbuf_t for reply payload assembly. Signed-off-by: Enrico Weigelt, metux IT consult --- Xi/listdev.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/Xi/listdev.c b/Xi/listdev.c index d9ed0acd2f..8c83abf990 100644 --- a/Xi/listdev.c +++ b/Xi/listdev.c @@ -57,7 +57,9 @@ SOFTWARE. #include #include +#include "dix/dix_priv.h" #include "dix/input_priv.h" +#include "dix/rpcbuf_priv.h" #include "inputstr.h" /* DeviceIntPtr */ #include "XIstubs.h" @@ -320,7 +322,7 @@ ProcXListInputDevices(ClientPtr client) int namesize = 1; /* need 1 extra byte for strcpy */ int i = 0, size = 0; int total_length; - char *devbuf, *classbuf, *namebuf, *savbuf; + char *classbuf, *namebuf; Bool *skip; xDeviceInfo *dev; DeviceIntPtr d; @@ -352,12 +354,18 @@ ProcXListInputDevices(ClientPtr client) numdevs++; } + x_rpcbuf_t rpcbuf = { .swapped = client->swapped, .err_clear = TRUE }; + /* allocate space for reply */ total_length = numdevs * sizeof(xDeviceInfo) + size + namesize; - devbuf = (char *) calloc(1, total_length); + char *devbuf = x_rpcbuf_reserve(&rpcbuf, total_length); + if (!devbuf) { + free(skip); + return BadAlloc; + } + classbuf = devbuf + (numdevs * sizeof(xDeviceInfo)); namebuf = classbuf + size; - savbuf = devbuf; /* fill in and send reply */ i = 0; @@ -376,22 +384,12 @@ ProcXListInputDevices(ClientPtr client) ListDeviceInfo(client, d, dev++, &devbuf, &classbuf, &namebuf); } - xListInputDevicesReply rep = { - .repType = X_Reply, + free(skip); + + xListInputDevicesReply reply = { .RepType = X_ListInputDevices, - .sequenceNumber = client->sequence, .ndevices = numdevs, - .length = bytes_to_int32(total_length), }; - if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - } - - WriteToClient(client, sizeof(xListInputDevicesReply), &rep); - WriteToClient(client, total_length, savbuf); - free(savbuf); - free(skip); - return Success; + return X_SEND_REPLY_WITH_RPCBUF(client, reply, rpcbuf); }