From bca6d2ddcd9135a57d97ea55cc05315d233dbb30 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 14 Aug 2025 13:15:21 +0200 Subject: [PATCH] vidmode: ProcVidModeGetMonitor(): create reply struct right before send Move the declaration of the reply struct down to after the payload has been finally assembled, so we don't need extra payload size compuation anymore. Signed-off-by: Enrico Weigelt, metux IT consult --- Xext/vidmode.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/Xext/vidmode.c b/Xext/vidmode.c index 45e03b352..5d0608b75 100644 --- a/Xext/vidmode.c +++ b/Xext/vidmode.c @@ -40,6 +40,7 @@ from Kaleb S. KEITHLEY #include "dix/dix_priv.h" #include "dix/rpcbuf_priv.h" #include "os/log_priv.h" +#include "os/osdep.h" #include "misc.h" #include "dixstruct.h" @@ -1228,24 +1229,6 @@ ProcVidModeGetMonitor(ClientPtr client) const char *vendorStr = (const char*)pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_VENDOR, 0).ptr; const char *modelStr = (const char*)pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_MODEL, 0).ptr; - const int vendorLength = (vendorStr ? strlen(vendorStr) : 0); - const int modelLength = (modelStr ? strlen(modelStr) : 0); - - const int nVendorItems = bytes_to_int32(vendorLength); - const int nModelItems = bytes_to_int32(modelLength); - - xXF86VidModeGetMonitorReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .nhsync = nHsync, - .nvsync = nVrefresh, - .vendorLength = vendorLength, - .modelLength = modelLength, - .length = bytes_to_int32(sizeof(xXF86VidModeGetMonitorReply) - - sizeof(xGenericReply)) - + nHsync + nVrefresh + nVendorItems + nModelItems - }; - x_rpcbuf_t rpcbuf = { .swapped = client->swapped, .err_clear = TRUE }; for (int i = 0; i < nHsync; i++) { @@ -1268,6 +1251,18 @@ ProcVidModeGetMonitor(ClientPtr client) if (rpcbuf.error) return BadAlloc; + xXF86VidModeGetMonitorReply rep = { + .type = X_Reply, + .sequenceNumber = client->sequence, + .nhsync = nHsync, + .nvsync = nVrefresh, + .vendorLength = x_safe_strlen(vendorStr), + .modelLength = x_safe_strlen(modelStr), + .length = bytes_to_int32(sizeof(xXF86VidModeGetMonitorReply) - + sizeof(xGenericReply)) + + x_rpcbuf_wsize_units(&rpcbuf) + }; + if (client->swapped) { swaps(&rep.sequenceNumber); swapl(&rep.length);