From 727da90141b40070b7b39722e2887b30d3cd757a Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 13 May 2025 14:40:34 +0200 Subject: [PATCH] (!1972) randr: simplify reply assembly in ProcRRListProviderProperties() Moving payload buffer assembly right into the same branch where the buffer is allocated, so making the whole code flow easier to understand. Also moving the byteswap there (when the fields should still be in CPU cache), instead of having some callback doing it much later, so even more simplication. As a nice by-product, that's also reducing some analyzer noise. Signed-off-by: Enrico Weigelt, metux IT consult --- randr/rrproviderproperty.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/randr/rrproviderproperty.c b/randr/rrproviderproperty.c index 84bb724e0..1638ff4ca 100644 --- a/randr/rrproviderproperty.c +++ b/randr/rrproviderproperty.c @@ -335,7 +335,7 @@ int ProcRRListProviderProperties(ClientPtr client) { REQUEST(xRRListProviderPropertiesReq); - Atom *pAtoms = NULL, *temppAtoms; + Atom *pAtoms = NULL; int numProps = 0; RRProviderPtr provider; RRPropertyPtr prop; @@ -346,9 +346,20 @@ ProcRRListProviderProperties(ClientPtr client) for (prop = provider->properties; prop; prop = prop->next) numProps++; - if (numProps) - if (!(pAtoms = xallocarray(numProps, sizeof(Atom)))) + + const Bool swapped = client->swapped; + + if (numProps) { + if (!(pAtoms = calloc(numProps, sizeof(Atom)))) return BadAlloc; + Atom *temppAtoms = pAtoms; + for (prop = provider->properties; prop; prop = prop->next) { + *temppAtoms = prop->propertyName; + if (swapped) + swapl(temppAtoms); + temppAtoms++; + } + } xRRListProviderPropertiesReply rep = { .type = X_Reply, @@ -356,21 +367,16 @@ ProcRRListProviderProperties(ClientPtr client) .length = bytes_to_int32(numProps * sizeof(Atom)), .nAtoms = numProps }; - if (client->swapped) { + if (swapped) { swaps(&rep.sequenceNumber); swapl(&rep.length); swaps(&rep.nAtoms); } - temppAtoms = pAtoms; - for (prop = provider->properties; prop; prop = prop->next) - *temppAtoms++ = prop->propertyName; WriteToClient(client, sizeof(xRRListProviderPropertiesReply), (char *) &rep); - if (numProps) { - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, numProps * sizeof(Atom), pAtoms); - free(pAtoms); - } + WriteToClient(client, numProps * sizeof(Atom), pAtoms); + + free(pAtoms); return Success; }