From 0c3d3856cc39003f89993841beef63498776c0a2 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 17 Jul 2024 11:07:27 +0200 Subject: [PATCH] dbe: ProcDbeGetVisualInfo() collect payload in buffer before writing The payload lengths is already known, so we can easily collect the data in a stack buffer and only need one WriteToClient() operation. This also clears the road for further simplification/unification of the reply sending code, coming with follow-up commits. Signed-off-by: Enrico Weigelt, metux IT consult --- dbe/dbe.c | 59 ++++++++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/dbe/dbe.c b/dbe/dbe.c index 298639896..ce987fb95 100644 --- a/dbe/dbe.c +++ b/dbe/dbe.c @@ -618,44 +618,41 @@ ProcDbeGetVisualInfo(ClientPtr client) /* Send off reply. */ WriteToClient(client, sizeof(xDbeGetVisualInfoReply), &rep); - for (i = 0; i < count; i++) { - CARD32 data32; + { + char buf[length]; + char *walk = buf; - /* For each screen in the reply, send off the visual info */ + for (i = 0; i < count; i++) { + /* For each screen in the reply, send off the visual info */ - /* Send off number of visuals. */ - data32 = (CARD32) pScrVisInfo[i].count; + /* Send off number of visuals. */ + *(CARD32*)walk = pScrVisInfo[i].count; + if (client->swapped) { swapl((CARD32*)walk); } + walk += sizeof(CARD32); - if (client->swapped) { - swapl(&data32); - } + /* Now send off visual info items. */ + for (j = 0; j < pScrVisInfo[i].count; j++) { + xDbeVisInfo *visInfo = (xDbeVisInfo*)walk; - WriteToClient(client, sizeof(CARD32), &data32); - - /* Now send off visual info items. */ - for (j = 0; j < pScrVisInfo[i].count; j++) { - xDbeVisInfo visInfo; - - /* Copy the data in the client data structure to a protocol - * data structure. We will send data to the client from the - * protocol data structure. - */ - - visInfo.visualID = (CARD32) pScrVisInfo[i].visinfo[j].visual; - visInfo.depth = (CARD8) pScrVisInfo[i].visinfo[j].depth; - visInfo.perfLevel = (CARD8) pScrVisInfo[i].visinfo[j].perflevel; - - if (client->swapped) { - swapl(&visInfo.visualID); - - /* We do not need to swap depth and perfLevel since they are - * already 1 byte quantities. + /* Copy the data in the client data structure to a protocol + * data structure. We will send data to the client from the + * protocol data structure. */ - } - /* Write visualID(32), depth(8), perfLevel(8), and pad(16). */ - WriteToClient(client, 2 * sizeof(CARD32), &visInfo.visualID); + visInfo->visualID = pScrVisInfo[i].visinfo[j].visual; + visInfo->depth = pScrVisInfo[i].visinfo[j].depth; + visInfo->perfLevel = pScrVisInfo[i].visinfo[j].perflevel; + + if (client->swapped) { + swapl(&visInfo->visualID); + + /* We do not need to swap depth and perfLevel since they are + * already 1 byte quantities. + */ + } + } } + WriteToClient(client, sizeof(buf), buf); } rc = Success;