randr: handle -Wanalyzer-null-dereference in ProcRRListProviderProperties()

Reported in #1817:
xwayland-24.1.6/redhat-linux-build/../randr/rrproviderproperty.c:419:9:
 warning[-Wanalyzer-null-dereference]: dereference of NULL ‘temppAtoms’

The NULL dereference was flagged because the compiler didn't realize that
the loop to dereference the pointer would have 0 iterations if the
pointer hadn't been allocated.  Moving it inside the if (numProps) check
made the dereference condition match the allocation condition so that the
gcc static analyzer was satisfied.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2165>
This commit is contained in:
Alan Coopersmith 2026-03-30 16:14:05 -07:00 committed by Marge Bot
parent 3cd7892e91
commit d7775b5682

View file

@ -391,7 +391,7 @@ int
ProcRRListProviderProperties(ClientPtr client)
{
REQUEST(xRRListProviderPropertiesReq);
Atom *pAtoms = NULL, *temppAtoms;
Atom *pAtoms = NULL;
xRRListProviderPropertiesReply rep;
int numProps = 0;
RRProviderPtr provider;
@ -418,12 +418,13 @@ ProcRRListProviderProperties(ClientPtr client)
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) {
Atom *temppAtoms = pAtoms;
for (prop = provider->properties; prop; prop = prop->next)
*temppAtoms++ = prop->propertyName;
client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
WriteSwappedDataToClient(client, numProps * sizeof(Atom), pAtoms);
free(pAtoms);