randr: RROutputSetClones(): 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:34:50 +02:00
parent 5b13d85464
commit 3279b81d7b

View File

@ -120,7 +120,6 @@ RROutputCreate(ScreenPtr pScreen,
Bool Bool
RROutputSetClones(RROutputPtr output, RROutputPtr * clones, int numClones) RROutputSetClones(RROutputPtr output, RROutputPtr * clones, int numClones)
{ {
RROutputPtr *newClones;
int i; int i;
if (numClones == output->numClones) { if (numClones == output->numClones) {
@ -130,15 +129,16 @@ RROutputSetClones(RROutputPtr output, RROutputPtr * clones, int numClones)
if (i == numClones) if (i == numClones)
return TRUE; return TRUE;
} }
RROutputPtr *newClones = NULL;
if (numClones) { if (numClones) {
newClones = xallocarray(numClones, sizeof(RROutputPtr)); newClones = xallocarray(numClones, sizeof(RROutputPtr));
if (!newClones) if (!newClones)
return FALSE; return FALSE;
memcpy(newClones, clones, numClones * sizeof(RROutputPtr));
} }
else
newClones = NULL;
free(output->clones); free(output->clones);
memcpy(newClones, clones, numClones * sizeof(RROutputPtr));
output->clones = newClones; output->clones = newClones;
output->numClones = numClones; output->numClones = numClones;
RROutputChanged(output, TRUE); RROutputChanged(output, TRUE);