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 <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-05-13 14:40:34 +02:00
parent 2e05296905
commit 67b78a9f58

View File

@ -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);
WriteToClient(client, numProps * sizeof(Atom), pAtoms);
free(pAtoms);
}
return Success;
}