From ca9e23c2635244c8ebf2b2904f14b392e9149c6d 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 5527e0328..7af737480 100644 --- a/randr/rroutput.c +++ b/randr/rroutput.c @@ -438,14 +438,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; @@ -457,6 +455,8 @@ ProcRRGetOutputInfo(ClientPtr client) pScreen = output->pScreen; pScrPriv = rrGetScrPriv(pScreen); + CARD8 *extra = NULL; + if (leased) { rep = (xRRGetOutputInfoReply) { .type = X_Reply, @@ -474,11 +474,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, @@ -507,13 +504,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; @@ -534,7 +530,7 @@ ProcRRGetOutputInfo(ClientPtr client) swapl(&clones[i]); } } - memcpy(name, output->name, output->nameLength); + if (client->swapped) { swaps(&rep.sequenceNumber); swapl(&rep.length);