From df85b516c4411e0fb94f67a8b17af6fd3286ce6a Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 13 May 2025 14:40:34 +0200 Subject: [PATCH] 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 92f1ef97b..c8b1ee350 100644 --- a/randr/rrproviderproperty.c +++ b/randr/rrproviderproperty.c @@ -385,7 +385,7 @@ int ProcRRListProviderProperties(ClientPtr client) { REQUEST(xRRListProviderPropertiesReq); - Atom *pAtoms = NULL, *temppAtoms; + Atom *pAtoms = NULL; int numProps = 0; RRProviderPtr provider; RRPropertyPtr prop; @@ -396,9 +396,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, @@ -406,21 +417,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; }