From 1e47daf592ba2a2496315ce6789197784ee8cd45 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 0fdb21fef..b33fc0dd7 100644 --- a/randr/rroutput.c +++ b/randr/rroutput.c @@ -148,7 +148,6 @@ Bool RROutputSetModes(RROutputPtr output, RRModePtr * modes, int numModes, int numPreferred) { - RRModePtr *newModes; int i; if (numModes == output->numModes && numPreferred == output->numPreferred) { @@ -162,19 +161,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;