Xext: xres: use static initialization and scoped ars
* use static initialization where applicable * drop unneeded setting of zero values * use scoped variables Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
6e1236dd10
commit
d37ce05b94
75
Xext/xres.c
75
Xext/xres.c
|
@ -196,16 +196,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);
|
||||
|
@ -219,18 +218,14 @@ ProcXResQueryVersion(ClientPtr client)
|
|||
static int
|
||||
ProcXResQueryClients(ClientPtr client)
|
||||
{
|
||||
/* REQUEST(xXResQueryClientsReq); */
|
||||
xXResQueryClientsReply rep;
|
||||
int i, num_clients;
|
||||
|
||||
REQUEST_SIZE_MATCH(xXResQueryClientsReq);
|
||||
|
||||
int *current_clients = calloc(currentMaxClients, sizeof(int));
|
||||
if (!current_clients)
|
||||
return BadAlloc;
|
||||
|
||||
num_clients = 0;
|
||||
for (i = 0; i < currentMaxClients; i++) {
|
||||
int num_clients = 0;
|
||||
for (int i = 0; i < currentMaxClients; i++) {
|
||||
if (clients[i]) {
|
||||
if (XaceHookClientAccess(client, clients[i], DixReadAccess) == Success) {
|
||||
current_clients[num_clients] = i;
|
||||
|
@ -239,7 +234,7 @@ ProcXResQueryClients(ClientPtr client)
|
|||
}
|
||||
}
|
||||
|
||||
rep = (xXResQueryClientsReply) {
|
||||
xXResQueryClientsReply rep = {
|
||||
.type = X_Reply,
|
||||
.sequenceNumber = client->sequence,
|
||||
.length = bytes_to_int32(num_clients * sz_xXResClient),
|
||||
|
@ -255,7 +250,7 @@ ProcXResQueryClients(ClientPtr client)
|
|||
if (num_clients) {
|
||||
xXResClient scratch;
|
||||
|
||||
for (i = 0; i < num_clients; i++) {
|
||||
for (int i = 0; i < num_clients; i++) {
|
||||
scratch.resource_base = clients[current_clients[i]]->clientAsMask;
|
||||
scratch.resource_mask = RESOURCE_ID_MASK;
|
||||
|
||||
|
@ -302,9 +297,6 @@ static int
|
|||
ProcXResQueryClientResources(ClientPtr client)
|
||||
{
|
||||
REQUEST(xXResQueryClientResourcesReq);
|
||||
xXResQueryClientResourcesReply rep;
|
||||
int i, num_types;
|
||||
|
||||
REQUEST_SIZE_MATCH(xXResQueryClientResourcesReq);
|
||||
|
||||
ClientPtr resClient = dixClientForXID(stuff->xid);
|
||||
|
@ -322,14 +314,13 @@ ProcXResQueryClientResources(ClientPtr client)
|
|||
|
||||
FindAllClientResources(resClient, ResFindAllRes, counts);
|
||||
|
||||
num_types = 0;
|
||||
|
||||
for (i = 0; i <= lastResourceType; i++) {
|
||||
int num_types = 0;
|
||||
for (int 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),
|
||||
|
@ -346,7 +337,7 @@ ProcXResQueryClientResources(ClientPtr client)
|
|||
if (num_types) {
|
||||
xXResType scratch;
|
||||
|
||||
for (i = 0; i < lastResourceType; i++) {
|
||||
for (int i = 0; i < lastResourceType; i++) {
|
||||
if (!counts[i])
|
||||
continue;
|
||||
|
||||
|
@ -381,8 +372,6 @@ static int
|
|||
ProcXResQueryClientPixmapBytes(ClientPtr client)
|
||||
{
|
||||
REQUEST(xXResQueryClientPixmapBytesReq);
|
||||
xXResQueryClientPixmapBytesReply rep;
|
||||
|
||||
REQUEST_SIZE_MATCH(xXResQueryClientPixmapBytesReq);
|
||||
|
||||
ClientPtr owner = dixClientForXID(stuff->xid);
|
||||
|
@ -397,15 +386,12 @@ ProcXResQueryClientPixmapBytes(ClientPtr client)
|
|||
FindAllClientResources(owner, 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) {
|
||||
|
@ -464,9 +450,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);
|
||||
}
|
||||
|
@ -478,7 +465,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 */
|
||||
|
@ -507,9 +493,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));
|
||||
|
@ -538,9 +521,7 @@ ConstructClientIds(ClientPtr client,
|
|||
int numSpecs, xXResClientIdSpec* specs,
|
||||
ConstructClientIdCtx *ctx)
|
||||
{
|
||||
int specIdx;
|
||||
|
||||
for (specIdx = 0; specIdx < numSpecs; ++specIdx) {
|
||||
for (int specIdx = 0; specIdx < numSpecs; ++specIdx) {
|
||||
if (specs[specIdx].client == 0) {
|
||||
int c;
|
||||
for (c = 0; c < currentMaxClients; ++c) {
|
||||
|
@ -583,7 +564,6 @@ ProcXResQueryClientIds (ClientPtr client)
|
|||
REQUEST(xXResQueryClientIdsReq);
|
||||
|
||||
xXResClientIdSpec *specs = (void*) ((char*) stuff + sizeof(*stuff));
|
||||
int rc;
|
||||
ConstructClientIdCtx ctx;
|
||||
|
||||
InitConstructClientIdCtx(&ctx);
|
||||
|
@ -592,18 +572,18 @@ ProcXResQueryClientIds (ClientPtr client)
|
|||
REQUEST_FIXED_SIZE(xXResQueryClientIdsReq,
|
||||
stuff->numSpecs * sizeof(specs[0]));
|
||||
|
||||
rc = ConstructClientIds(client, stuff->numSpecs, specs, &ctx);
|
||||
int 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);
|
||||
|
@ -650,12 +630,11 @@ static void
|
|||
SwapXResQueryResourceBytes(struct xorg_list *response)
|
||||
{
|
||||
struct xorg_list *it = response->next;
|
||||
int c;
|
||||
|
||||
while (it != response) {
|
||||
xXResResourceSizeValue *value = FRAGMENT_DATA(it);
|
||||
it = it->next;
|
||||
for (c = 0; c < value->numCrossReferences; ++c) {
|
||||
for (int c = 0; c < value->numCrossReferences; ++c) {
|
||||
xXResResourceSizeSpec *spec = FRAGMENT_DATA(it);
|
||||
SwapXResResourceSizeSpec(spec);
|
||||
it = it->next;
|
||||
|
@ -858,8 +837,7 @@ static void
|
|||
ConstructClientResourceBytes(ClientPtr aboutClient,
|
||||
ConstructResourceBytesCtx *ctx)
|
||||
{
|
||||
int specIdx;
|
||||
for (specIdx = 0; specIdx < ctx->numSpecs; ++specIdx) {
|
||||
for (int specIdx = 0; specIdx < ctx->numSpecs; ++specIdx) {
|
||||
xXResResourceIdSpec* spec = ctx->specs + specIdx;
|
||||
if (spec->resource) {
|
||||
/* these specs are handled elsewhere */
|
||||
|
@ -891,8 +869,7 @@ ConstructClientResourceBytes(ClientPtr aboutClient,
|
|||
static void
|
||||
ConstructResourceBytesByResource(XID aboutClient, ConstructResourceBytesCtx *ctx)
|
||||
{
|
||||
int specIdx;
|
||||
for (specIdx = 0; specIdx < ctx->numSpecs; ++specIdx) {
|
||||
for (int specIdx = 0; specIdx < ctx->numSpecs; ++specIdx) {
|
||||
xXResResourceIdSpec *spec = ctx->specs + specIdx;
|
||||
if (spec->resource) {
|
||||
ClientPtr client = dixClientForXID(spec->resource);
|
||||
|
@ -952,11 +929,9 @@ static int
|
|||
ProcXResQueryResourceBytes (ClientPtr client)
|
||||
{
|
||||
REQUEST(xXResQueryResourceBytesReq);
|
||||
|
||||
int rc;
|
||||
ConstructResourceBytesCtx ctx;
|
||||
|
||||
REQUEST_AT_LEAST_SIZE(xXResQueryResourceBytesReq);
|
||||
|
||||
ConstructResourceBytesCtx ctx;
|
||||
if (stuff->numSpecs > UINT32_MAX / sizeof(ctx.specs[0]))
|
||||
return BadLength;
|
||||
REQUEST_FIXED_SIZE(xXResQueryResourceBytesReq,
|
||||
|
@ -969,7 +944,7 @@ ProcXResQueryResourceBytes (ClientPtr client)
|
|||
return BadAlloc;
|
||||
}
|
||||
|
||||
rc = ConstructResourceBytes(stuff->client, &ctx);
|
||||
int rc = ConstructResourceBytes(stuff->client, &ctx);
|
||||
|
||||
if (rc == Success) {
|
||||
xXResQueryResourceBytesReply rep = {
|
||||
|
|
Loading…
Reference in New Issue