From 16b7e77a764247c0909d58cc5e7c457b7d635cf3 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 28 Aug 2024 13:35:20 +0200 Subject: [PATCH] (!1665) glx: DoQueryContext(): determine reply length from buffer size The reply length (in units as well as bytes) can safely be determined at compile time, by using sizeof() operator. No need for unnecessarily complicated shifting bits back and forth. Signed-off-by: Enrico Weigelt, metux IT consult --- glx/glxcmds.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/glx/glxcmds.c b/glx/glxcmds.c index 3e6b11865..5c0107f4d 100644 --- a/glx/glxcmds.c +++ b/glx/glxcmds.c @@ -1660,7 +1660,6 @@ DoQueryContext(__GLXclientState * cl, GLXContextID gcId) ClientPtr client = cl->client; __GLXcontext *ctx; CARD32 sendBuf[GLX_QUERY_NPROPS * 2]; - int nReplyBytes; int err; if (!validGlxContext(cl->client, gcId, DixReadAccess, &ctx, &err)) @@ -1669,11 +1668,10 @@ DoQueryContext(__GLXclientState * cl, GLXContextID gcId) xGLXQueryContextInfoEXTReply reply = { .type = X_Reply, .sequenceNumber = client->sequence, - .length = GLX_QUERY_NPROPS << 1, + .length = bytes_to_int32(sizeof(sendBuf)), .n = GLX_QUERY_NPROPS, }; - nReplyBytes = reply.length << 2; sendBuf[0] = GLX_SHARE_CONTEXT_EXT; sendBuf[1] = (int) (ctx->share_id); sendBuf[2] = GLX_VISUAL_ID_EXT; @@ -1686,20 +1684,18 @@ DoQueryContext(__GLXclientState * cl, GLXContextID gcId) sendBuf[9] = (int) (ctx->renderType); if (client->swapped) { - int length = reply.length; - __GLX_DECLARE_SWAP_VARIABLES; __GLX_DECLARE_SWAP_ARRAY_VARIABLES; __GLX_SWAP_SHORT(&reply.sequenceNumber); __GLX_SWAP_INT(&reply.length); __GLX_SWAP_INT(&reply.n); WriteToClient(client, sizeof(xGLXQueryContextInfoEXTReply), &reply); - __GLX_SWAP_INT_ARRAY(sendBuf, length); - WriteToClient(client, length << 2, sendBuf); + __GLX_SWAP_INT_ARRAY(sendBuf, sizeof(sendBuf) / sizeof(CARD32)); + WriteToClient(client, sizeof(sendBuf), sendBuf); } else { WriteToClient(client, sizeof(xGLXQueryContextInfoEXTReply), &reply); - WriteToClient(client, nReplyBytes, sendBuf); + WriteToClient(client, sizeof(sendBuf), sendBuf); } return Success;