randr: simplify extra payload copying in ProcRRGetOutputInfo()

Make it a bit easier to understand how exactly the name string is copied into
the reply payload: just do the little memcpy() right where the target position
is decided any the rest of the payload is filled.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-05-13 11:47:56 +02:00
parent b67dabef12
commit 6b5c64d273

View File

@ -437,14 +437,12 @@ ProcRRGetOutputInfo(ClientPtr client)
REQUEST(xRRGetOutputInfoReq);
xRRGetOutputInfoReply rep;
RROutputPtr output;
CARD8 *extra;
unsigned long extraLen;
ScreenPtr pScreen;
rrScrPrivPtr pScrPriv;
RRCrtc *crtcs;
RRMode *modes;
RROutput *clones;
char *name;
int i;
Bool leased;
@ -456,6 +454,8 @@ ProcRRGetOutputInfo(ClientPtr client)
pScreen = output->pScreen;
pScrPriv = rrGetScrPriv(pScreen);
CARD8 *extra = NULL;
if (leased) {
rep = (xRRGetOutputInfoReply) {
.type = X_Reply,
@ -473,11 +473,8 @@ ProcRRGetOutputInfo(ClientPtr client)
extra = calloc(1, extraLen);
if (!extra)
return BadAlloc;
memcpy(extra, output->name, output->nameLength);
}
else
extra = NULL;
name = (char *) extra;
} else {
rep = (xRRGetOutputInfoReply) {
.type = X_Reply,
@ -506,13 +503,12 @@ ProcRRGetOutputInfo(ClientPtr client)
if (!extra)
return BadAlloc;
}
else
extra = NULL;
crtcs = (RRCrtc *) extra;
modes = (RRMode *) (crtcs + output->numCrtcs);
clones = (RROutput *) (modes + output->numModes + output->numUserModes);
name = (char *) (clones + output->numClones);
memcpy((clones + output->numClones), output->name, output->nameLength);
for (i = 0; i < output->numCrtcs; i++) {
crtcs[i] = output->crtcs[i]->id;
@ -533,7 +529,7 @@ ProcRRGetOutputInfo(ClientPtr client)
swapl(&clones[i]);
}
}
memcpy(name, output->name, output->nameLength);
if (client->swapped) {
swaps(&rep.sequenceNumber);
swapl(&rep.length);