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 <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-05-13 12:32:52 +02:00
parent 6b5c64d273
commit b535db955a

View File

@ -468,13 +468,14 @@ ProcRRGetOutputInfo(ClientPtr client)
.nameLength = output->nameLength .nameLength = output->nameLength
}; };
extraLen = bytes_to_int32(rep.nameLength) << 2; extraLen = bytes_to_int32(rep.nameLength) << 2;
if (extraLen) { if (!extraLen)
rep.length += bytes_to_int32(extraLen); goto sendout;
extra = calloc(1, extraLen);
if (!extra) rep.length += bytes_to_int32(extraLen);
return BadAlloc; extra = calloc(1, extraLen);
memcpy(extra, output->name, output->nameLength); if (!extra)
} return BadAlloc;
memcpy(extra, output->name, output->nameLength);
} else { } else {
rep = (xRRGetOutputInfoReply) { rep = (xRRGetOutputInfoReply) {
.type = X_Reply, .type = X_Reply,
@ -497,12 +498,13 @@ ProcRRGetOutputInfo(ClientPtr client)
output->numModes + output->numUserModes + output->numModes + output->numUserModes +
output->numClones + bytes_to_int32(rep.nameLength)) << 2); output->numClones + bytes_to_int32(rep.nameLength)) << 2);
if (extraLen) { if (!extraLen)
rep.length += bytes_to_int32(extraLen); goto sendout;
extra = calloc(1, extraLen);
if (!extra) rep.length += bytes_to_int32(extraLen);
return BadAlloc; extra = calloc(1, extraLen);
} if (!extra)
return BadAlloc;
crtcs = (RRCrtc *) extra; crtcs = (RRCrtc *) extra;
modes = (RRMode *) (crtcs + output->numCrtcs); modes = (RRMode *) (crtcs + output->numCrtcs);
@ -515,6 +517,7 @@ ProcRRGetOutputInfo(ClientPtr client)
if (client->swapped) if (client->swapped)
swapl(&crtcs[i]); swapl(&crtcs[i]);
} }
for (i = 0; i < output->numModes + output->numUserModes; i++) { for (i = 0; i < output->numModes + output->numUserModes; i++) {
if (i < output->numModes) if (i < output->numModes)
modes[i] = output->modes[i]->mode.id; modes[i] = output->modes[i]->mode.id;
@ -530,6 +533,7 @@ ProcRRGetOutputInfo(ClientPtr client)
} }
} }
sendout:
if (client->swapped) { if (client->swapped) {
swaps(&rep.sequenceNumber); swaps(&rep.sequenceNumber);
swapl(&rep.length); swapl(&rep.length);
@ -543,11 +547,10 @@ ProcRRGetOutputInfo(ClientPtr client)
swaps(&rep.nClones); swaps(&rep.nClones);
swaps(&rep.nameLength); swaps(&rep.nameLength);
} }
WriteToClient(client, sizeof(xRRGetOutputInfoReply), &rep); WriteToClient(client, sizeof(xRRGetOutputInfoReply), &rep);
if (extraLen) { WriteToClient(client, extraLen, extra);
WriteToClient(client, extraLen, extra); free(extra);
free(extra);
}
return Success; return Success;
} }