From e6ade4f97d7161d85ebdc4f0760c8ddef50d3dbe 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 74ad91991..cdd809846 100644 --- a/glx/clientinfo.c +++ b/glx/clientinfo.c @@ -43,7 +43,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 37d14fe99..f29b514e5 100644 --- a/glx/createcontext.c +++ b/glx/createcontext.c @@ -116,7 +116,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 5691ed0ae..635f145c2 100644 --- a/glx/glxcmds.c +++ b/glx/glxcmds.c @@ -722,7 +722,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; } @@ -761,7 +761,7 @@ __glXDisp_QueryVersion(__GLXclientState * cl, GLbyte * pc) __GLX_SWAP_INT(&reply.minorVersion); } - WriteToClient(client, sz_xGLXQueryVersionReply, &reply); + WriteToClient(client, sizeof(xGLXQueryVersionReply), &reply); return Success; } @@ -932,7 +932,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]; @@ -1045,7 +1045,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; @@ -1694,12 +1694,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); } @@ -1937,12 +1937,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); } @@ -2022,8 +2022,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; @@ -2132,18 +2132,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; @@ -2398,12 +2398,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); } @@ -2470,13 +2470,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 882dcc8c4..2928186c4 100644 --- a/glx/indirect_util.c +++ b/glx/indirect_util.c @@ -138,7 +138,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); @@ -186,7 +186,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 72cad7800..55194cc15 100644 --- a/glx/single2.c +++ b/glx/single2.c @@ -200,7 +200,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 b97fb884e..4b26a43ca 100644 --- a/glx/single2swap.c +++ b/glx/single2swap.c @@ -217,7 +217,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; }