From acec1156b3d9e5616bd0a578077b2638f3e4979a Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 13 May 2025 11:38:46 +0200 Subject: [PATCH] randr: RROutputSetModes(): 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 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/randr/rroutput.c b/randr/rroutput.c index 078d6798d..a800b8ba8 100644 --- a/randr/rroutput.c +++ b/randr/rroutput.c @@ -149,7 +149,6 @@ Bool RROutputSetModes(RROutputPtr output, RRModePtr * modes, int numModes, int numPreferred) { - RRModePtr *newModes; int i; if (numModes == output->numModes && numPreferred == output->numPreferred) { @@ -163,19 +162,19 @@ RROutputSetModes(RROutputPtr output, } } + RRModePtr *newModes = NULL; if (numModes) { newModes = xallocarray(numModes, sizeof(RRModePtr)); if (!newModes) return FALSE; + memcpy(newModes, modes, numModes * sizeof(RRModePtr)); } - else - newModes = NULL; + if (output->modes) { for (i = 0; i < output->numModes; i++) RRModeDestroy(output->modes[i]); free(output->modes); } - memcpy(newModes, modes, numModes * sizeof(RRModePtr)); output->modes = newModes; output->numModes = numModes; output->numPreferred = numPreferred;