From 3af9346edb3082dae2d9eeac0075bef28f3b256b Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 17 Jul 2024 12:52:01 +0200 Subject: [PATCH] Xext: xres: ProcXResQueryClients() simplify payload write out Collect the few bits in a local array, so one WriteToClient() call is sufficient. That's also easing further simplifications in upcoming commits. Signed-off-by: Enrico Weigelt, metux IT consult --- Xext/xres.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Xext/xres.c b/Xext/xres.c index 617574b55..ceb7b57d6 100644 --- a/Xext/xres.c +++ b/Xext/xres.c @@ -244,25 +244,31 @@ ProcXResQueryClients(ClientPtr client) swapl(&rep.length); swapl(&rep.num_clients); } - WriteToClient(client, sizeof(xXResQueryClientsReply), &rep); + + xXResClient *scratch = NULL; if (num_clients) { - xXResClient scratch; + scratch = calloc(sizeof(xXResClient), num_clients); + if (!scratch) { + free(current_clients); + return BadAlloc; + } for (int i = 0; i < num_clients; i++) { - scratch.resource_base = clients[current_clients[i]]->clientAsMask; - scratch.resource_mask = RESOURCE_ID_MASK; + scratch[i].resource_base = clients[current_clients[i]]->clientAsMask; + scratch[i].resource_mask = RESOURCE_ID_MASK; if (client->swapped) { - swapl(&scratch.resource_base); - swapl(&scratch.resource_mask); + swapl(&scratch[i].resource_base); + swapl(&scratch[i].resource_mask); } - WriteToClient(client, sz_xXResClient, &scratch); } } + WriteToClient(client, sizeof(xXResQueryClientsReply), &rep); + WriteToClient(client, sizeof(xXResClient) * num_clients, scratch); free(current_clients); - + free(scratch); return Success; }