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 <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-07-17 11:07:27 +02:00
parent 3f37b07864
commit 0c3d3856cc

View File

@ -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;