From 2ae56e0238044ad8713d478089b6e6b8483a8338 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Mon, 8 Jul 2024 16:41:39 +0200 Subject: [PATCH] (!1601) Xext: xres: use static initialization * use static initialization where applicable * drop unneeded setting of zero values Signed-off-by: Enrico Weigelt, metux IT consult --- Xext/xres.c | 54 +++++++++++++++++++---------------------------------- 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/Xext/xres.c b/Xext/xres.c index dd776ba62..c93f2bcf7 100644 --- a/Xext/xres.c +++ b/Xext/xres.c @@ -193,16 +193,15 @@ DestroyConstructResourceBytesCtx(ConstructResourceBytesCtx *ctx) static int ProcXResQueryVersion(ClientPtr client) { + REQUEST_SIZE_MATCH(xXResQueryVersionReq); + xXResQueryVersionReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, - .length = 0, .server_major = SERVER_XRES_MAJOR_VERSION, .server_minor = SERVER_XRES_MINOR_VERSION }; - REQUEST_SIZE_MATCH(xXResQueryVersionReq); - if (client->swapped) { swaps(&rep.sequenceNumber); swapl(&rep.length); @@ -216,16 +215,13 @@ ProcXResQueryVersion(ClientPtr client) static int ProcXResQueryClients(ClientPtr client) { - /* REQUEST(xXResQueryClientsReq); */ - xXResQueryClientsReply rep; int *current_clients; - int i, num_clients; + int i, num_clients = 0; REQUEST_SIZE_MATCH(xXResQueryClientsReq); current_clients = xallocarray(currentMaxClients, sizeof(int)); - num_clients = 0; for (i = 0; i < currentMaxClients; i++) { if (clients[i]) { current_clients[num_clients] = i; @@ -233,7 +229,7 @@ ProcXResQueryClients(ClientPtr client) } } - rep = (xXResQueryClientsReply) { + xXResQueryClientsReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, .length = bytes_to_int32(num_clients * sz_xXResClient), @@ -296,12 +292,11 @@ static int ProcXResQueryClientResources(ClientPtr client) { REQUEST(xXResQueryClientResourcesReq); - xXResQueryClientResourcesReply rep; - int i, clientID, num_types; - int *counts; - REQUEST_SIZE_MATCH(xXResQueryClientResourcesReq); + int i, clientID, num_types = 0; + int *counts; + clientID = CLIENT_ID(stuff->xid); if ((clientID >= currentMaxClients) || !clients[clientID]) { @@ -313,14 +308,12 @@ ProcXResQueryClientResources(ClientPtr client) FindAllClientResources(clients[clientID], ResFindAllRes, counts); - num_types = 0; - for (i = 0; i <= lastResourceType; i++) { if (counts[i]) num_types++; } - rep = (xXResQueryClientResourcesReply) { + xXResQueryClientResourcesReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, .length = bytes_to_int32(num_types * sz_xXResType), @@ -372,12 +365,11 @@ static int ProcXResQueryClientPixmapBytes(ClientPtr client) { REQUEST(xXResQueryClientPixmapBytesReq); - xXResQueryClientPixmapBytesReply rep; - int clientID; - unsigned long bytes; - REQUEST_SIZE_MATCH(xXResQueryClientPixmapBytesReq); + int clientID; + unsigned long bytes = 0; + clientID = CLIENT_ID(stuff->xid); if ((clientID >= currentMaxClients) || !clients[clientID]) { @@ -385,20 +377,15 @@ ProcXResQueryClientPixmapBytes(ClientPtr client) return BadValue; } - bytes = 0; - FindAllClientResources(clients[clientID], ResFindResourcePixmaps, (void *) (&bytes)); - rep = (xXResQueryClientPixmapBytesReply) { + xXResQueryClientPixmapBytesReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, - .length = 0, .bytes = bytes, #ifdef _XSERVER64 .bytes_overflow = bytes >> 32 -#else - .bytes_overflow = 0 #endif }; if (client->swapped) { @@ -457,9 +444,10 @@ static Bool ConstructClientIdValue(ClientPtr sendClient, ClientPtr client, CARD32 mask, ConstructClientIdCtx *ctx) { - xXResClientIdValue rep; + xXResClientIdValue rep = { + .spec.client = client->clientAsMask, + }; - rep.spec.client = client->clientAsMask; if (client->swapped) { swapl (&rep.spec.client); } @@ -471,7 +459,6 @@ ConstructClientIdValue(ClientPtr sendClient, ClientPtr client, CARD32 mask, } rep.spec.mask = X_XResClientXIDMask; - rep.length = 0; if (sendClient->swapped) { swapl (&rep.spec.mask); /* swapl (&rep.length, n); - not required for rep.length = 0 */ @@ -500,9 +487,6 @@ ConstructClientIdValue(ClientPtr sendClient, ClientPtr client, CARD32 mask, if (sendClient->swapped) { swapl (&rep.spec.mask); swapl (&rep.length); - } - - if (sendClient->swapped) { swapl (value); } memcpy(ptr, &rep, sizeof(rep)); @@ -585,15 +569,15 @@ ProcXResQueryClientIds (ClientPtr client) rc = ConstructClientIds(client, stuff->numSpecs, specs, &ctx); if (rc == Success) { - xXResQueryClientIdsReply rep = { + assert((ctx.resultBytes & 3) == 0); + + xXResQueryClientIdsReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, .length = bytes_to_int32(ctx.resultBytes), .numIds = ctx.numIds }; - assert((ctx.resultBytes & 3) == 0); - if (client->swapped) { swaps (&rep.sequenceNumber); swapl (&rep.length); @@ -950,11 +934,11 @@ static int ProcXResQueryResourceBytes (ClientPtr client) { REQUEST(xXResQueryResourceBytesReq); + REQUEST_AT_LEAST_SIZE(xXResQueryResourceBytesReq); int rc; ConstructResourceBytesCtx ctx; - REQUEST_AT_LEAST_SIZE(xXResQueryResourceBytesReq); if (stuff->numSpecs > UINT32_MAX / sizeof(ctx.specs[0])) return BadLength; REQUEST_FIXED_SIZE(xXResQueryResourceBytesReq,