ProcRRListOutputProperties: skip atom walk if the list is empty

pAtoms is only allocated if numProps was non-zero, so move the walk
through the property list to copy atoms to it inside the if (numProps)

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
Tested-by: Daniel Stone <daniel@fooishbar.org>
This commit is contained in:
Alan Coopersmith 2012-07-09 19:12:42 -07:00
parent 15bc13c8d0
commit 2e739a8870

View File

@ -378,7 +378,7 @@ int
ProcRRListOutputProperties(ClientPtr client) ProcRRListOutputProperties(ClientPtr client)
{ {
REQUEST(xRRListOutputPropertiesReq); REQUEST(xRRListOutputPropertiesReq);
Atom *pAtoms = NULL, *temppAtoms; Atom *pAtoms = NULL;
xRRListOutputPropertiesReply rep; xRRListOutputPropertiesReply rep;
int numProps = 0; int numProps = 0;
RROutputPtr output; RROutputPtr output;
@ -403,12 +403,14 @@ ProcRRListOutputProperties(ClientPtr client)
swapl(&rep.length); swapl(&rep.length);
swaps(&rep.nAtoms); swaps(&rep.nAtoms);
} }
temppAtoms = pAtoms;
for (prop = output->properties; prop; prop = prop->next)
*temppAtoms++ = prop->propertyName;
WriteToClient(client, sizeof(xRRListOutputPropertiesReply), &rep); WriteToClient(client, sizeof(xRRListOutputPropertiesReply), &rep);
if (numProps) { if (numProps) {
/* Copy property name atoms to reply buffer */
Atom *temppAtoms = pAtoms;
for (prop = output->properties; prop; prop = prop->next)
*temppAtoms++ = prop->propertyName;
client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
WriteSwappedDataToClient(client, numProps * sizeof(Atom), pAtoms); WriteSwappedDataToClient(client, numProps * sizeof(Atom), pAtoms);
free(pAtoms); free(pAtoms);