From 58d82e22ae373f6b3539467857c15ca368df9acd 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 df9207f67..ebe63b033 100644 --- a/glx/glxcmds.c +++ b/glx/glxcmds.c @@ -1662,7 +1662,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)) @@ -1671,11 +1670,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; @@ -1688,20 +1686,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;