From 6b5c64d273e248c172dbb776d2868b60a552c6e3 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 13 May 2025 11:47:56 +0200 Subject: [PATCH] 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 --- randr/rroutput.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/randr/rroutput.c b/randr/rroutput.c index 82558e143..cd5c11b3b 100644 --- a/randr/rroutput.c +++ b/randr/rroutput.c @@ -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);