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
|
static int
|
||||||
ProcXResQueryVersion(ClientPtr client)
|
ProcXResQueryVersion(ClientPtr client)
|
||||||
{
|
{
|
||||||
|
REQUEST_SIZE_MATCH(xXResQueryVersionReq);
|
||||||
|
|
||||||
xXResQueryVersionReply rep = {
|
xXResQueryVersionReply rep = {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.sequenceNumber = client->sequence,
|
.sequenceNumber = client->sequence,
|
||||||
.length = 0,
|
|
||||||
.server_major = SERVER_XRES_MAJOR_VERSION,
|
.server_major = SERVER_XRES_MAJOR_VERSION,
|
||||||
.server_minor = SERVER_XRES_MINOR_VERSION
|
.server_minor = SERVER_XRES_MINOR_VERSION
|
||||||
};
|
};
|
||||||
|
|
||||||
REQUEST_SIZE_MATCH(xXResQueryVersionReq);
|
|
||||||
|
|
||||||
if (client->swapped) {
|
if (client->swapped) {
|
||||||
swaps(&rep.sequenceNumber);
|
swaps(&rep.sequenceNumber);
|
||||||
swapl(&rep.length);
|
swapl(&rep.length);
|
||||||
|
@ -219,18 +218,14 @@ ProcXResQueryVersion(ClientPtr client)
|
||||||
static int
|
static int
|
||||||
ProcXResQueryClients(ClientPtr client)
|
ProcXResQueryClients(ClientPtr client)
|
||||||
{
|
{
|
||||||
/* REQUEST(xXResQueryClientsReq); */
|
|
||||||
xXResQueryClientsReply rep;
|
|
||||||
int i, num_clients;
|
|
||||||
|
|
||||||
REQUEST_SIZE_MATCH(xXResQueryClientsReq);
|
REQUEST_SIZE_MATCH(xXResQueryClientsReq);
|
||||||
|
|
||||||
int *current_clients = calloc(currentMaxClients, sizeof(int));
|
int *current_clients = calloc(currentMaxClients, sizeof(int));
|
||||||
if (!current_clients)
|
if (!current_clients)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
|
||||||
num_clients = 0;
|
int num_clients = 0;
|
||||||
for (i = 0; i < currentMaxClients; i++) {
|
for (int i = 0; i < currentMaxClients; i++) {
|
||||||
if (clients[i]) {
|
if (clients[i]) {
|
||||||
if (XaceHookClientAccess(client, clients[i], DixReadAccess) == Success) {
|
if (XaceHookClientAccess(client, clients[i], DixReadAccess) == Success) {
|
||||||
current_clients[num_clients] = i;
|
current_clients[num_clients] = i;
|
||||||
|
@ -239,7 +234,7 @@ ProcXResQueryClients(ClientPtr client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rep = (xXResQueryClientsReply) {
|
xXResQueryClientsReply rep = {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.sequenceNumber = client->sequence,
|
.sequenceNumber = client->sequence,
|
||||||
.length = bytes_to_int32(num_clients * sz_xXResClient),
|
.length = bytes_to_int32(num_clients * sz_xXResClient),
|
||||||
|
@ -255,7 +250,7 @@ ProcXResQueryClients(ClientPtr client)
|
||||||
if (num_clients) {
|
if (num_clients) {
|
||||||
xXResClient scratch;
|
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_base = clients[current_clients[i]]->clientAsMask;
|
||||||
scratch.resource_mask = RESOURCE_ID_MASK;
|
scratch.resource_mask = RESOURCE_ID_MASK;
|
||||||
|
|
||||||
|
@ -302,9 +297,6 @@ static int
|
||||||
ProcXResQueryClientResources(ClientPtr client)
|
ProcXResQueryClientResources(ClientPtr client)
|
||||||
{
|
{
|
||||||
REQUEST(xXResQueryClientResourcesReq);
|
REQUEST(xXResQueryClientResourcesReq);
|
||||||
xXResQueryClientResourcesReply rep;
|
|
||||||
int i, num_types;
|
|
||||||
|
|
||||||
REQUEST_SIZE_MATCH(xXResQueryClientResourcesReq);
|
REQUEST_SIZE_MATCH(xXResQueryClientResourcesReq);
|
||||||
|
|
||||||
ClientPtr resClient = dixClientForXID(stuff->xid);
|
ClientPtr resClient = dixClientForXID(stuff->xid);
|
||||||
|
@ -322,14 +314,13 @@ ProcXResQueryClientResources(ClientPtr client)
|
||||||
|
|
||||||
FindAllClientResources(resClient, ResFindAllRes, counts);
|
FindAllClientResources(resClient, ResFindAllRes, counts);
|
||||||
|
|
||||||
num_types = 0;
|
int num_types = 0;
|
||||||
|
for (int i = 0; i <= lastResourceType; i++) {
|
||||||
for (i = 0; i <= lastResourceType; i++) {
|
|
||||||
if (counts[i])
|
if (counts[i])
|
||||||
num_types++;
|
num_types++;
|
||||||
}
|
}
|
||||||
|
|
||||||
rep = (xXResQueryClientResourcesReply) {
|
xXResQueryClientResourcesReply rep = {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.sequenceNumber = client->sequence,
|
.sequenceNumber = client->sequence,
|
||||||
.length = bytes_to_int32(num_types * sz_xXResType),
|
.length = bytes_to_int32(num_types * sz_xXResType),
|
||||||
|
@ -346,7 +337,7 @@ ProcXResQueryClientResources(ClientPtr client)
|
||||||
if (num_types) {
|
if (num_types) {
|
||||||
xXResType scratch;
|
xXResType scratch;
|
||||||
|
|
||||||
for (i = 0; i < lastResourceType; i++) {
|
for (int i = 0; i < lastResourceType; i++) {
|
||||||
if (!counts[i])
|
if (!counts[i])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -381,8 +372,6 @@ static int
|
||||||
ProcXResQueryClientPixmapBytes(ClientPtr client)
|
ProcXResQueryClientPixmapBytes(ClientPtr client)
|
||||||
{
|
{
|
||||||
REQUEST(xXResQueryClientPixmapBytesReq);
|
REQUEST(xXResQueryClientPixmapBytesReq);
|
||||||
xXResQueryClientPixmapBytesReply rep;
|
|
||||||
|
|
||||||
REQUEST_SIZE_MATCH(xXResQueryClientPixmapBytesReq);
|
REQUEST_SIZE_MATCH(xXResQueryClientPixmapBytesReq);
|
||||||
|
|
||||||
ClientPtr owner = dixClientForXID(stuff->xid);
|
ClientPtr owner = dixClientForXID(stuff->xid);
|
||||||
|
@ -397,15 +386,12 @@ ProcXResQueryClientPixmapBytes(ClientPtr client)
|
||||||
FindAllClientResources(owner, ResFindResourcePixmaps,
|
FindAllClientResources(owner, ResFindResourcePixmaps,
|
||||||
(void *) (&bytes));
|
(void *) (&bytes));
|
||||||
|
|
||||||
rep = (xXResQueryClientPixmapBytesReply) {
|
xXResQueryClientPixmapBytesReply rep = {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.sequenceNumber = client->sequence,
|
.sequenceNumber = client->sequence,
|
||||||
.length = 0,
|
|
||||||
.bytes = bytes,
|
.bytes = bytes,
|
||||||
#ifdef _XSERVER64
|
#ifdef _XSERVER64
|
||||||
.bytes_overflow = bytes >> 32
|
.bytes_overflow = bytes >> 32
|
||||||
#else
|
|
||||||
.bytes_overflow = 0
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
if (client->swapped) {
|
if (client->swapped) {
|
||||||
|
@ -464,9 +450,10 @@ static Bool
|
||||||
ConstructClientIdValue(ClientPtr sendClient, ClientPtr client, CARD32 mask,
|
ConstructClientIdValue(ClientPtr sendClient, ClientPtr client, CARD32 mask,
|
||||||
ConstructClientIdCtx *ctx)
|
ConstructClientIdCtx *ctx)
|
||||||
{
|
{
|
||||||
xXResClientIdValue rep;
|
xXResClientIdValue rep = {
|
||||||
|
.spec.client = client->clientAsMask,
|
||||||
|
};
|
||||||
|
|
||||||
rep.spec.client = client->clientAsMask;
|
|
||||||
if (client->swapped) {
|
if (client->swapped) {
|
||||||
swapl (&rep.spec.client);
|
swapl (&rep.spec.client);
|
||||||
}
|
}
|
||||||
|
@ -478,7 +465,6 @@ ConstructClientIdValue(ClientPtr sendClient, ClientPtr client, CARD32 mask,
|
||||||
}
|
}
|
||||||
|
|
||||||
rep.spec.mask = X_XResClientXIDMask;
|
rep.spec.mask = X_XResClientXIDMask;
|
||||||
rep.length = 0;
|
|
||||||
if (sendClient->swapped) {
|
if (sendClient->swapped) {
|
||||||
swapl (&rep.spec.mask);
|
swapl (&rep.spec.mask);
|
||||||
/* swapl (&rep.length, n); - not required for rep.length = 0 */
|
/* swapl (&rep.length, n); - not required for rep.length = 0 */
|
||||||
|
@ -507,9 +493,6 @@ ConstructClientIdValue(ClientPtr sendClient, ClientPtr client, CARD32 mask,
|
||||||
if (sendClient->swapped) {
|
if (sendClient->swapped) {
|
||||||
swapl (&rep.spec.mask);
|
swapl (&rep.spec.mask);
|
||||||
swapl (&rep.length);
|
swapl (&rep.length);
|
||||||
}
|
|
||||||
|
|
||||||
if (sendClient->swapped) {
|
|
||||||
swapl (value);
|
swapl (value);
|
||||||
}
|
}
|
||||||
memcpy(ptr, &rep, sizeof(rep));
|
memcpy(ptr, &rep, sizeof(rep));
|
||||||
|
@ -538,9 +521,7 @@ ConstructClientIds(ClientPtr client,
|
||||||
int numSpecs, xXResClientIdSpec* specs,
|
int numSpecs, xXResClientIdSpec* specs,
|
||||||
ConstructClientIdCtx *ctx)
|
ConstructClientIdCtx *ctx)
|
||||||
{
|
{
|
||||||
int specIdx;
|
for (int specIdx = 0; specIdx < numSpecs; ++specIdx) {
|
||||||
|
|
||||||
for (specIdx = 0; specIdx < numSpecs; ++specIdx) {
|
|
||||||
if (specs[specIdx].client == 0) {
|
if (specs[specIdx].client == 0) {
|
||||||
int c;
|
int c;
|
||||||
for (c = 0; c < currentMaxClients; ++c) {
|
for (c = 0; c < currentMaxClients; ++c) {
|
||||||
|
@ -583,7 +564,6 @@ ProcXResQueryClientIds (ClientPtr client)
|
||||||
REQUEST(xXResQueryClientIdsReq);
|
REQUEST(xXResQueryClientIdsReq);
|
||||||
|
|
||||||
xXResClientIdSpec *specs = (void*) ((char*) stuff + sizeof(*stuff));
|
xXResClientIdSpec *specs = (void*) ((char*) stuff + sizeof(*stuff));
|
||||||
int rc;
|
|
||||||
ConstructClientIdCtx ctx;
|
ConstructClientIdCtx ctx;
|
||||||
|
|
||||||
InitConstructClientIdCtx(&ctx);
|
InitConstructClientIdCtx(&ctx);
|
||||||
|
@ -592,18 +572,18 @@ ProcXResQueryClientIds (ClientPtr client)
|
||||||
REQUEST_FIXED_SIZE(xXResQueryClientIdsReq,
|
REQUEST_FIXED_SIZE(xXResQueryClientIdsReq,
|
||||||
stuff->numSpecs * sizeof(specs[0]));
|
stuff->numSpecs * sizeof(specs[0]));
|
||||||
|
|
||||||
rc = ConstructClientIds(client, stuff->numSpecs, specs, &ctx);
|
int rc = ConstructClientIds(client, stuff->numSpecs, specs, &ctx);
|
||||||
|
|
||||||
if (rc == Success) {
|
if (rc == Success) {
|
||||||
xXResQueryClientIdsReply rep = {
|
assert((ctx.resultBytes & 3) == 0);
|
||||||
|
|
||||||
|
xXResQueryClientIdsReply rep = {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.sequenceNumber = client->sequence,
|
.sequenceNumber = client->sequence,
|
||||||
.length = bytes_to_int32(ctx.resultBytes),
|
.length = bytes_to_int32(ctx.resultBytes),
|
||||||
.numIds = ctx.numIds
|
.numIds = ctx.numIds
|
||||||
};
|
};
|
||||||
|
|
||||||
assert((ctx.resultBytes & 3) == 0);
|
|
||||||
|
|
||||||
if (client->swapped) {
|
if (client->swapped) {
|
||||||
swaps (&rep.sequenceNumber);
|
swaps (&rep.sequenceNumber);
|
||||||
swapl (&rep.length);
|
swapl (&rep.length);
|
||||||
|
@ -650,12 +630,11 @@ static void
|
||||||
SwapXResQueryResourceBytes(struct xorg_list *response)
|
SwapXResQueryResourceBytes(struct xorg_list *response)
|
||||||
{
|
{
|
||||||
struct xorg_list *it = response->next;
|
struct xorg_list *it = response->next;
|
||||||
int c;
|
|
||||||
|
|
||||||
while (it != response) {
|
while (it != response) {
|
||||||
xXResResourceSizeValue *value = FRAGMENT_DATA(it);
|
xXResResourceSizeValue *value = FRAGMENT_DATA(it);
|
||||||
it = it->next;
|
it = it->next;
|
||||||
for (c = 0; c < value->numCrossReferences; ++c) {
|
for (int c = 0; c < value->numCrossReferences; ++c) {
|
||||||
xXResResourceSizeSpec *spec = FRAGMENT_DATA(it);
|
xXResResourceSizeSpec *spec = FRAGMENT_DATA(it);
|
||||||
SwapXResResourceSizeSpec(spec);
|
SwapXResResourceSizeSpec(spec);
|
||||||
it = it->next;
|
it = it->next;
|
||||||
|
@ -858,8 +837,7 @@ static void
|
||||||
ConstructClientResourceBytes(ClientPtr aboutClient,
|
ConstructClientResourceBytes(ClientPtr aboutClient,
|
||||||
ConstructResourceBytesCtx *ctx)
|
ConstructResourceBytesCtx *ctx)
|
||||||
{
|
{
|
||||||
int specIdx;
|
for (int specIdx = 0; specIdx < ctx->numSpecs; ++specIdx) {
|
||||||
for (specIdx = 0; specIdx < ctx->numSpecs; ++specIdx) {
|
|
||||||
xXResResourceIdSpec* spec = ctx->specs + specIdx;
|
xXResResourceIdSpec* spec = ctx->specs + specIdx;
|
||||||
if (spec->resource) {
|
if (spec->resource) {
|
||||||
/* these specs are handled elsewhere */
|
/* these specs are handled elsewhere */
|
||||||
|
@ -891,8 +869,7 @@ ConstructClientResourceBytes(ClientPtr aboutClient,
|
||||||
static void
|
static void
|
||||||
ConstructResourceBytesByResource(XID aboutClient, ConstructResourceBytesCtx *ctx)
|
ConstructResourceBytesByResource(XID aboutClient, ConstructResourceBytesCtx *ctx)
|
||||||
{
|
{
|
||||||
int specIdx;
|
for (int specIdx = 0; specIdx < ctx->numSpecs; ++specIdx) {
|
||||||
for (specIdx = 0; specIdx < ctx->numSpecs; ++specIdx) {
|
|
||||||
xXResResourceIdSpec *spec = ctx->specs + specIdx;
|
xXResResourceIdSpec *spec = ctx->specs + specIdx;
|
||||||
if (spec->resource) {
|
if (spec->resource) {
|
||||||
ClientPtr client = dixClientForXID(spec->resource);
|
ClientPtr client = dixClientForXID(spec->resource);
|
||||||
|
@ -952,11 +929,9 @@ static int
|
||||||
ProcXResQueryResourceBytes (ClientPtr client)
|
ProcXResQueryResourceBytes (ClientPtr client)
|
||||||
{
|
{
|
||||||
REQUEST(xXResQueryResourceBytesReq);
|
REQUEST(xXResQueryResourceBytesReq);
|
||||||
|
|
||||||
int rc;
|
|
||||||
ConstructResourceBytesCtx ctx;
|
|
||||||
|
|
||||||
REQUEST_AT_LEAST_SIZE(xXResQueryResourceBytesReq);
|
REQUEST_AT_LEAST_SIZE(xXResQueryResourceBytesReq);
|
||||||
|
|
||||||
|
ConstructResourceBytesCtx ctx;
|
||||||
if (stuff->numSpecs > UINT32_MAX / sizeof(ctx.specs[0]))
|
if (stuff->numSpecs > UINT32_MAX / sizeof(ctx.specs[0]))
|
||||||
return BadLength;
|
return BadLength;
|
||||||
REQUEST_FIXED_SIZE(xXResQueryResourceBytesReq,
|
REQUEST_FIXED_SIZE(xXResQueryResourceBytesReq,
|
||||||
|
@ -969,7 +944,7 @@ ProcXResQueryResourceBytes (ClientPtr client)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = ConstructResourceBytes(stuff->client, &ctx);
|
int rc = ConstructResourceBytes(stuff->client, &ctx);
|
||||||
|
|
||||||
if (rc == Success) {
|
if (rc == Success) {
|
||||||
xXResQueryResourceBytesReply rep = {
|
xXResQueryResourceBytesReply rep = {
|
||||||
|
|
Loading…
Reference in New Issue