From 3279b81d7bbffee4626c4cdab73eaedb4bc6e067 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 13 May 2025 11:34:50 +0200 Subject: [PATCH] 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 --- randr/rroutput.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/randr/rroutput.c b/randr/rroutput.c index 8397aac74..078d6798d 100644 --- a/randr/rroutput.c +++ b/randr/rroutput.c @@ -120,7 +120,6 @@ RROutputCreate(ScreenPtr pScreen, Bool RROutputSetClones(RROutputPtr output, RROutputPtr * clones, int numClones) { - RROutputPtr *newClones; int i; if (numClones == output->numClones) { @@ -130,15 +129,16 @@ RROutputSetClones(RROutputPtr output, RROutputPtr * clones, int numClones) if (i == numClones) return TRUE; } + + RROutputPtr *newClones = NULL; if (numClones) { newClones = xallocarray(numClones, sizeof(RROutputPtr)); if (!newClones) return FALSE; + memcpy(newClones, clones, numClones * sizeof(RROutputPtr)); } - else - newClones = NULL; + free(output->clones); - memcpy(newClones, clones, numClones * sizeof(RROutputPtr)); output->clones = newClones; output->numClones = numClones; RROutputChanged(output, TRUE);