From 6dd0b813adfd8516bdfc35f8897b9ad633cb0d3a 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 8d0f05498..0fdb21fef 100644 --- a/randr/rroutput.c +++ b/randr/rroutput.c @@ -119,7 +119,6 @@ RROutputCreate(ScreenPtr pScreen, Bool RROutputSetClones(RROutputPtr output, RROutputPtr * clones, int numClones) { - RROutputPtr *newClones; int i; if (numClones == output->numClones) { @@ -129,15 +128,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);