From 6cc0b62f2bf2fa406cb050921edbafb8a743de1e Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 28 Aug 2024 13:27:23 +0200 Subject: [PATCH] (!1665) glx: use sizeof() for reply struct The reply struct's size can safely be determined by the sizeof() operator, so no need for using an extra define here. Making the code easier to read and also open the door for future convenience macros that might determine the buffer size on their own. Signed-off-by: Enrico Weigelt, metux IT consult --- glx/clientinfo.c | 2 +- glx/createcontext.c | 2 +- glx/glxcmds.c | 34 +++++++++++++++++----------------- glx/indirect_util.c | 4 ++-- glx/single2.c | 2 +- glx/single2swap.c | 2 +- glx/unpack.h | 2 +- glx/vndcmds.c | 4 ++-- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/glx/clientinfo.c b/glx/clientinfo.c index 3dcabf844..53f4c603f 100644 --- a/glx/clientinfo.c +++ b/glx/clientinfo.c @@ -41,7 +41,7 @@ set_client_info(__GLXclientState * cl, xGLXSetClientInfoARBReq * req, /* Verify that the size of the packet matches the size inferred from the * sizes specified for the various fields. */ - size = sz_xGLXSetClientInfoARBReq; + size = sizeof(xGLXSetClientInfoARBReq); size = safe_add(size, safe_mul(req->numVersions, bytes_per_version)); size = safe_add(size, safe_pad(req->numGLExtensionBytes)); size = safe_add(size, safe_pad(req->numGLXExtensionBytes)); diff --git a/glx/createcontext.c b/glx/createcontext.c index 185bd6bb2..59ecf3eaf 100644 --- a/glx/createcontext.c +++ b/glx/createcontext.c @@ -114,7 +114,7 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc) /* Verify that the size of the packet matches the size inferred from the * sizes specified for the various fields. */ - const unsigned expected_size = (sz_xGLXCreateContextAttribsARBReq + const unsigned expected_size = (sizeof(xGLXCreateContextAttribsARBReq) + (req->numAttribs * 8)) / 4; if (req->length != expected_size) diff --git a/glx/glxcmds.c b/glx/glxcmds.c index 907b1cc3a..34a8b6fef 100644 --- a/glx/glxcmds.c +++ b/glx/glxcmds.c @@ -720,7 +720,7 @@ __glXDisp_IsDirect(__GLXclientState * cl, GLbyte * pc) __GLX_SWAP_SHORT(&reply.sequenceNumber); __GLX_SWAP_INT(&reply.length); } - WriteToClient(client, sz_xGLXIsDirectReply, &reply); + WriteToClient(client, sizeof(xGLXIsDirectReply), &reply); return Success; } @@ -759,7 +759,7 @@ __glXDisp_QueryVersion(__GLXclientState * cl, GLbyte * pc) __GLX_SWAP_INT(&reply.minorVersion); } - WriteToClient(client, sz_xGLXQueryVersionReply, &reply); + WriteToClient(client, sizeof(xGLXQueryVersionReply), &reply); return Success; } @@ -930,7 +930,7 @@ __glXDisp_GetVisualConfigs(__GLXclientState * cl, GLbyte * pc) __GLX_SWAP_INT(&reply.numProps); } - WriteToClient(client, sz_xGLXGetVisualConfigsReply, &reply); + WriteToClient(client, sizeof(xGLXGetVisualConfigsReply), &reply); for (i = 0; i < pGlxScreen->numVisuals; i++) { modes = pGlxScreen->visuals[i]; @@ -1043,7 +1043,7 @@ DoGetFBConfigs(__GLXclientState * cl, unsigned screen) __GLX_SWAP_INT(&reply.numAttribs); } - WriteToClient(client, sz_xGLXGetFBConfigsReply, &reply); + WriteToClient(client, sizeof(xGLXGetFBConfigsReply), &reply); for (modes = pGlxScreen->fbconfigs; modes != NULL; modes = modes->next) { p = 0; @@ -1692,12 +1692,12 @@ DoQueryContext(__GLXclientState * cl, GLXContextID gcId) __GLX_SWAP_SHORT(&reply.sequenceNumber); __GLX_SWAP_INT(&reply.length); __GLX_SWAP_INT(&reply.n); - WriteToClient(client, sz_xGLXQueryContextInfoEXTReply, &reply); + WriteToClient(client, sizeof(xGLXQueryContextInfoEXTReply), &reply); __GLX_SWAP_INT_ARRAY((int *) sendBuf, length); WriteToClient(client, length << 2, sendBuf); } else { - WriteToClient(client, sz_xGLXQueryContextInfoEXTReply, &reply); + WriteToClient(client, sizeof(xGLXQueryContextInfoEXTReply), &reply); WriteToClient(client, nReplyBytes, sendBuf); } @@ -1935,12 +1935,12 @@ DoGetDrawableAttributes(__GLXclientState * cl, XID drawId) __GLX_SWAP_SHORT(&reply.sequenceNumber); __GLX_SWAP_INT(&reply.length); __GLX_SWAP_INT(&reply.numAttribs); - WriteToClient(client, sz_xGLXGetDrawableAttributesReply, &reply); + WriteToClient(client, sizeof(xGLXGetDrawableAttributesReply), &reply); __GLX_SWAP_INT_ARRAY((int *) attributes, length); WriteToClient(client, length << 2, attributes); } else { - WriteToClient(client, sz_xGLXGetDrawableAttributesReply, &reply); + WriteToClient(client, sizeof(xGLXGetDrawableAttributesReply), &reply); WriteToClient(client, reply.length * sizeof(CARD32), attributes); } @@ -2020,8 +2020,8 @@ __glXDisp_Render(__GLXclientState * cl, GLbyte * pc) } commandsDone = 0; - pc += sz_xGLXRenderReq; - left = (req->length << 2) - sz_xGLXRenderReq; + pc += sizeof(xGLXRenderReq); + left = (req->length << 2) - sizeof(xGLXRenderReq); while (left > 0) { __GLXrenderSizeData entry; int extra = 0; @@ -2130,18 +2130,18 @@ __glXDisp_RenderLarge(__GLXclientState * cl, GLbyte * pc) /* ** Check the request length. */ - if ((req->length << 2) != safe_pad(dataBytes) + sz_xGLXRenderLargeReq) { + if ((req->length << 2) != safe_pad(dataBytes) + sizeof(xGLXRenderLargeReq)) { client->errorValue = req->length; /* Reset in case this isn't 1st request. */ ResetLargeCommandStatus(glxc); return BadLength; } - pc += sz_xGLXRenderLargeReq; + pc += sizeof(xGLXRenderLargeReq); if (glxc->largeCmdRequestsSoFar == 0) { __GLXrenderSizeData entry; int extra = 0; - int left = (req->length << 2) - sz_xGLXRenderLargeReq; + int left = (req->length << 2) - sizeof(xGLXRenderLargeReq); int cmdlen; int err; @@ -2396,12 +2396,12 @@ __glXDisp_QueryExtensionsString(__GLXclientState * cl, GLbyte * pc) __GLX_SWAP_SHORT(&reply.sequenceNumber); __GLX_SWAP_INT(&reply.length); __GLX_SWAP_INT(&reply.n); - WriteToClient(client, sz_xGLXQueryExtensionsStringReply, &reply); + WriteToClient(client, sizeof(xGLXQueryExtensionsStringReply), &reply); __GLX_SWAP_INT_ARRAY((int *) buf, length); WriteToClient(client, length << 2, buf); } else { - WriteToClient(client, sz_xGLXQueryExtensionsStringReply, &reply); + WriteToClient(client, sizeof(xGLXQueryExtensionsStringReply), &reply); WriteToClient(client, (int) (length << 2), buf); } @@ -2468,13 +2468,13 @@ __glXDisp_QueryServerString(__GLXclientState * cl, GLbyte * pc) __GLX_SWAP_SHORT(&reply.sequenceNumber); __GLX_SWAP_INT(&reply.length); __GLX_SWAP_INT(&reply.n); - WriteToClient(client, sz_xGLXQueryServerStringReply, &reply); + WriteToClient(client, sizeof(xGLXQueryServerStringReply), &reply); /** no swap is needed for an array of chars **/ /* __GLX_SWAP_INT_ARRAY((int *)buf, length); */ WriteToClient(client, length << 2, buf); } else { - WriteToClient(client, sz_xGLXQueryServerStringReply, &reply); + WriteToClient(client, sizeof(xGLXQueryServerStringReply), &reply); WriteToClient(client, (int) (length << 2), buf); } diff --git a/glx/indirect_util.c b/glx/indirect_util.c index a63ce7eeb..0d4465886 100644 --- a/glx/indirect_util.c +++ b/glx/indirect_util.c @@ -136,7 +136,7 @@ __glXSendReply(ClientPtr client, const void *data, size_t elements, */ (void) memcpy(&reply.pad3, data, 8); - WriteToClient(client, sz_xGLXSingleReply, &reply); + WriteToClient(client, sizeof(xGLXSingleReply), &reply); if (reply_ints != 0) { WriteToClient(client, reply_ints * 4, data); @@ -184,7 +184,7 @@ __glXSendReplySwap(ClientPtr client, const void *data, size_t elements, */ (void) memcpy(&reply.pad3, data, 8); - WriteToClient(client, sz_xGLXSingleReply, &reply); + WriteToClient(client, sizeof(xGLXSingleReply), &reply); if (reply_ints != 0) { WriteToClient(client, reply_ints * 4, data); diff --git a/glx/single2.c b/glx/single2.c index ef355b470..18fd2c1bc 100644 --- a/glx/single2.c +++ b/glx/single2.c @@ -198,7 +198,7 @@ __glXDisp_RenderMode(__GLXclientState * cl, GLbyte * pc) .size = nitems, .newMode = newMode }; - WriteToClient(client, sz_xGLXRenderModeReply, &reply); + WriteToClient(client, sizeof(xGLXRenderModeReply), &reply); if (retBytes) { WriteToClient(client, retBytes, retBuffer); } diff --git a/glx/single2swap.c b/glx/single2swap.c index fc9e584b0..4bafd0dd5 100644 --- a/glx/single2swap.c +++ b/glx/single2swap.c @@ -215,7 +215,7 @@ __glXDispSwap_RenderMode(__GLXclientState * cl, GLbyte * pc) __GLX_SWAP_INT(&reply.retval); __GLX_SWAP_INT(&reply.size); __GLX_SWAP_INT(&reply.newMode); - WriteToClient(client, sz_xGLXRenderModeReply, &reply); + WriteToClient(client, sizeof(xGLXRenderModeReply), &reply); if (retBytes) { WriteToClient(client, retBytes, retBuffer); } diff --git a/glx/unpack.h b/glx/unpack.h index 9676e64c4..256073470 100644 --- a/glx/unpack.h +++ b/glx/unpack.h @@ -59,7 +59,7 @@ reply.sequenceNumber = client->sequence; #define __GLX_SEND_HEADER() \ - WriteToClient (client, sz_xGLXSingleReply, &reply); + WriteToClient (client, sizeof(xGLXSingleReply), &reply); #define __GLX_PUT_RETVAL(a) \ reply.retval = (a); diff --git a/glx/vndcmds.c b/glx/vndcmds.c index cb3732d2a..4ffa5f19f 100644 --- a/glx/vndcmds.c +++ b/glx/vndcmds.c @@ -110,7 +110,7 @@ static int dispatch_GLXQueryVersion(ClientPtr client) reply.majorVersion = GlxCheckSwap(client, 1); reply.minorVersion = GlxCheckSwap(client, 4); - WriteToClient(client, sz_xGLXQueryVersionReply, &reply); + WriteToClient(client, sizeof(xGLXQueryVersionReply), &reply); return Success; } @@ -272,7 +272,7 @@ static int CommonMakeCurrent(ClientPtr client, } reply.contextTag = GlxCheckSwap(client, reply.contextTag); - WriteToClient(client, sz_xGLXMakeCurrentReply, &reply); + WriteToClient(client, sizeof(xGLXMakeCurrentReply), &reply); return Success; }