From 08e62055ceb25d9321f714cb1f0f24c74043d204 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 16 Jul 2024 19:48:51 +0200 Subject: [PATCH] dbe: use REQUEST_HEAD_STRUCT and REQUEST_FIELD_* macros Use the new macros to make request struct parsing / field swapping much easier. Signed-off-by: Enrico Weigelt, metux IT consult --- dbe/dbe.c | 62 ++++++++++++++++++------------------------------------- 1 file changed, 20 insertions(+), 42 deletions(-) diff --git a/dbe/dbe.c b/dbe/dbe.c index 4a7a363d32..020ea94e18 100644 --- a/dbe/dbe.c +++ b/dbe/dbe.c @@ -112,7 +112,7 @@ DbeStubScreen(DbeScreenPrivPtr pDbeScreenPriv, int *nStubbedScreens) static int ProcDbeGetVersion(ClientPtr client) { - REQUEST_SIZE_MATCH(xDbeGetVersionReq); + X_REQUEST_HEAD_STRUCT(xDbeGetVersionReq); xDbeGetVersionReply reply = { .majorVersion = DBE_MAJOR_VERSION, @@ -148,13 +148,9 @@ ProcDbeGetVersion(ClientPtr client) static int ProcDbeAllocateBackBufferName(ClientPtr client) { - REQUEST(xDbeAllocateBackBufferNameReq); - REQUEST_SIZE_MATCH(xDbeAllocateBackBufferNameReq); - - if (client->swapped) { - swapl(&stuff->window); - swapl(&stuff->buffer); - } + X_REQUEST_HEAD_STRUCT(xDbeAllocateBackBufferNameReq); + X_REQUEST_FIELD_CARD32(window); + X_REQUEST_FIELD_CARD32(buffer); /* The window must be valid. */ WindowPtr pWin; @@ -355,11 +351,8 @@ ProcDbeAllocateBackBufferName(ClientPtr client) static int ProcDbeDeallocateBackBufferName(ClientPtr client) { - REQUEST(xDbeDeallocateBackBufferNameReq); - REQUEST_SIZE_MATCH(xDbeDeallocateBackBufferNameReq); - - if (client->swapped) - swapl(&stuff->buffer); + X_REQUEST_HEAD_STRUCT(xDbeDeallocateBackBufferNameReq); + X_REQUEST_FIELD_CARD32(buffer); DbeWindowPrivPtr pDbeWindowPriv; @@ -426,17 +419,18 @@ ProcDbeDeallocateBackBufferName(ClientPtr client) static int ProcDbeSwapBuffers(ClientPtr client) { - REQUEST(xDbeSwapBuffersReq); - REQUEST_AT_LEAST_SIZE(xDbeSwapBuffersReq); + X_REQUEST_HEAD_AT_LEAST(xDbeSwapBuffersReq); + X_REQUEST_FIELD_CARD32(n); + + if (stuff->n == 0) + return Success; + + if (stuff->n > UINT32_MAX / sizeof(DbeSwapInfoRec)) + return BadLength; + REQUEST_FIXED_SIZE(xDbeSwapBuffersReq, stuff->n * sizeof(xDbeSwapInfo)); if (client->swapped) { xDbeSwapInfo *pSwapInfo; - - swapl(&stuff->n); - if (stuff->n > UINT32_MAX / sizeof(DbeSwapInfoRec)) - return BadLength; - REQUEST_FIXED_SIZE(xDbeSwapBuffersReq, stuff->n * sizeof(xDbeSwapInfo)); - if (stuff->n != 0) { pSwapInfo = (xDbeSwapInfo *) stuff + 1; @@ -453,15 +447,6 @@ ProcDbeSwapBuffers(ClientPtr client) unsigned int nStuff = stuff->n; /* use local variable for performance. */ - if (nStuff == 0) { - REQUEST_SIZE_MATCH(xDbeSwapBuffersReq); - return Success; - } - - if (nStuff > UINT32_MAX / sizeof(DbeSwapInfoRec)) - return BadAlloc; - REQUEST_FIXED_SIZE(xDbeSwapBuffersReq, nStuff * sizeof(xDbeSwapInfo)); - /* Get to the swap info appended to the end of the request. */ xDbeSwapInfo* dbeSwapInfo = (xDbeSwapInfo *) &stuff[1]; @@ -559,13 +544,9 @@ ProcDbeSwapBuffers(ClientPtr client) static int ProcDbeGetVisualInfo(ClientPtr client) { - REQUEST(xDbeGetVisualInfoReq); - REQUEST_AT_LEAST_SIZE(xDbeGetVisualInfoReq); - - if (client->swapped) { - swapl(&stuff->n); - SwapRestL(stuff); - } + X_REQUEST_HEAD_AT_LEAST(xDbeGetVisualInfoReq); + X_REQUEST_FIELD_CARD32(n); + X_REQUEST_REST_CARD32(); DbeScreenPrivPtr pDbeScreenPriv; Drawable *drawables; @@ -675,11 +656,8 @@ clearRpcBuf: static int ProcDbeGetBackBufferAttributes(ClientPtr client) { - REQUEST(xDbeGetBackBufferAttributesReq); - REQUEST_SIZE_MATCH(xDbeGetBackBufferAttributesReq); - - if (client->swapped) - swapl(&stuff->buffer); + X_REQUEST_HEAD_STRUCT(xDbeGetBackBufferAttributesReq); + X_REQUEST_FIELD_CARD32(buffer); DbeWindowPrivPtr pDbeWindowPriv; int rc;