From b67dabef1224882cf1f9b2e55cd4ae0b98319b35 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 13 May 2025 11:39:55 +0200 Subject: [PATCH] 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 --- randr/rroutput.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/randr/rroutput.c b/randr/rroutput.c index a800b8ba8..82558e143 100644 --- a/randr/rroutput.c +++ b/randr/rroutput.c @@ -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; + memcpy(newCrtcs, crtcs, numCrtcs * sizeof(RRCrtcPtr)); } - else - newCrtcs = NULL; + free(output->crtcs); - memcpy(newCrtcs, crtcs, numCrtcs * sizeof(RRCrtcPtr)); output->crtcs = newCrtcs; output->numCrtcs = numCrtcs; RROutputChanged(output, TRUE);