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 <info@metux.net>
This commit is contained in:
parent
3279b81d7b
commit
acec1156b3
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue