randr: RROutputSetCrtcs(): simplify buffer allocation / copying

Instead of relying on memcpy() coping with NULL buffer when size == 0,
move the call to the branch where we actually have things to copy.

This also silences yet another analyzer warning.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-05-13 11:39:55 +02:00
parent acec1156b3
commit b67dabef12

View File

@ -251,7 +251,6 @@ RROutputDeleteUserMode(RROutputPtr output, RRModePtr mode)
Bool
RROutputSetCrtcs(RROutputPtr output, RRCrtcPtr * crtcs, int numCrtcs)
{
RRCrtcPtr *newCrtcs;
int i;
if (numCrtcs == output->numCrtcs) {
@ -261,15 +260,16 @@ RROutputSetCrtcs(RROutputPtr output, RRCrtcPtr * crtcs, int numCrtcs)
if (i == numCrtcs)
return TRUE;
}
RRCrtcPtr *newCrtcs = NULL;
if (numCrtcs) {
newCrtcs = xallocarray(numCrtcs, sizeof(RRCrtcPtr));
if (!newCrtcs)
return FALSE;
}
else
newCrtcs = NULL;
free(output->crtcs);
memcpy(newCrtcs, crtcs, numCrtcs * sizeof(RRCrtcPtr));
}
free(output->crtcs);
output->crtcs = newCrtcs;
output->numCrtcs = numCrtcs;
RROutputChanged(output, TRUE);