(submit/cleanup-vidmode-dispatch) Xext: vidmode: ProcVidModeGetMonitor(): write reply payload at once.

Collect up the puzzle piezes of the reply payload into to a temporary struct,
so we can send it as one block. This allows for further simplifications by
subsequent 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 14:56:40 +02:00
parent cfa82b85b0
commit 0dd817f62c

View File

@ -1245,16 +1245,11 @@ ProcVidModeGetMonitor(ClientPtr client)
pad_to_int32(modelLength)), pad_to_int32(modelLength)),
}; };
hsyncdata = calloc(nHsync, sizeof(CARD32)); CARD32 *hsyncdata = calloc(nHsync + nVrefresh, sizeof(CARD32));
if (!hsyncdata) { if (!hsyncdata) {
return BadAlloc; return BadAlloc;
} }
vsyncdata = calloc(nVrefresh, sizeof(CARD32)); vsyncdata = &hsyncdata[nHsync];
if (!vsyncdata) {
free(hsyncdata);
return BadAlloc;
}
for (i = 0; i < nHsync; i++) { for (i = 0; i < nHsync; i++) {
hsyncdata[i] = (unsigned short) (pVidMode->GetMonitorValue(pScreen, hsyncdata[i] = (unsigned short) (pVidMode->GetMonitorValue(pScreen,
@ -1276,22 +1271,12 @@ ProcVidModeGetMonitor(ClientPtr client)
if (client->swapped) { if (client->swapped) {
swaps(&rep.sequenceNumber); swaps(&rep.sequenceNumber);
swapl(&rep.length); swapl(&rep.length);
SwapLongs(hsyncdata, sizeof(hsyncdata)); SwapLongs(hsyncdata, nHsync + nVrefresh);
SwapLongs(vsyncdata, sizeof(vsyncdata));
} }
WriteToClient(client, SIZEOF(xXF86VidModeGetMonitorReply), &rep); WriteToClient(client, SIZEOF(xXF86VidModeGetMonitorReply), &rep);
WriteToClient(client, sizeof(hsyncdata), hsyncdata); WriteToClient(client, (nHsync + nVrefresh) * sizeof(CARD32), hsyncdata);
WriteToClient(client, sizeof(vsyncdata), vsyncdata);
if (rep.vendorLength)
WriteToClient(client, rep.vendorLength,
(pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_VENDOR, 0)).ptr);
if (rep.modelLength)
WriteToClient(client, rep.modelLength,
(pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_MODEL, 0)).ptr);
free(hsyncdata); free(hsyncdata);
free(vsyncdata);
return Success; return Success;
} }