From b535db955a10558b48ad00208d1a8b4b5b0367be Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 13 May 2025 12:32:52 +0200 Subject: [PATCH] randr: ProcRRGetOutputInfo() skip payload assembly when nothing to do If there's no extra payload to send, we can skip the whole payload assembly chain. Signed-off-by: Enrico Weigelt, metux IT consult --- randr/rroutput.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/randr/rroutput.c b/randr/rroutput.c index cd5c11b3b..ac3c59dd9 100644 --- a/randr/rroutput.c +++ b/randr/rroutput.c @@ -468,13 +468,14 @@ ProcRRGetOutputInfo(ClientPtr client) .nameLength = output->nameLength }; extraLen = bytes_to_int32(rep.nameLength) << 2; - if (extraLen) { - rep.length += bytes_to_int32(extraLen); - extra = calloc(1, extraLen); - if (!extra) - return BadAlloc; - memcpy(extra, output->name, output->nameLength); - } + if (!extraLen) + goto sendout; + + rep.length += bytes_to_int32(extraLen); + extra = calloc(1, extraLen); + if (!extra) + return BadAlloc; + memcpy(extra, output->name, output->nameLength); } else { rep = (xRRGetOutputInfoReply) { .type = X_Reply, @@ -497,12 +498,13 @@ ProcRRGetOutputInfo(ClientPtr client) output->numModes + output->numUserModes + output->numClones + bytes_to_int32(rep.nameLength)) << 2); - if (extraLen) { - rep.length += bytes_to_int32(extraLen); - extra = calloc(1, extraLen); - if (!extra) - return BadAlloc; - } + if (!extraLen) + goto sendout; + + rep.length += bytes_to_int32(extraLen); + extra = calloc(1, extraLen); + if (!extra) + return BadAlloc; crtcs = (RRCrtc *) extra; modes = (RRMode *) (crtcs + output->numCrtcs); @@ -515,6 +517,7 @@ ProcRRGetOutputInfo(ClientPtr client) if (client->swapped) swapl(&crtcs[i]); } + for (i = 0; i < output->numModes + output->numUserModes; i++) { if (i < output->numModes) modes[i] = output->modes[i]->mode.id; @@ -530,6 +533,7 @@ ProcRRGetOutputInfo(ClientPtr client) } } +sendout: if (client->swapped) { swaps(&rep.sequenceNumber); swapl(&rep.length); @@ -543,11 +547,10 @@ ProcRRGetOutputInfo(ClientPtr client) swaps(&rep.nClones); swaps(&rep.nameLength); } + WriteToClient(client, sizeof(xRRGetOutputInfoReply), &rep); - if (extraLen) { - WriteToClient(client, extraLen, extra); - free(extra); - } + WriteToClient(client, extraLen, extra); + free(extra); return Success; }