summaryrefslogtreecommitdiff
path: root/xserver/dix/resource.c
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@cvs.openbsd.org>2016-05-29 12:02:41 +0000
committerMatthieu Herrb <matthieu@cvs.openbsd.org>2016-05-29 12:02:41 +0000
commit4a991716ac65d28a68f9943d54c4b74ad0b58f65 (patch)
treec037c3fe64bb15ea67dbf03a96783a8b04085371 /xserver/dix/resource.c
parent549cb8bcb6bdd3a7d44f3b9fdc003df777b2b0d2 (diff)
Update to xserver 1.18.3. Tested by shadchin@ and naddy@.
Note that indirect GLX is now disbled by default.
Diffstat (limited to 'xserver/dix/resource.c')
-rw-r--r--xserver/dix/resource.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/xserver/dix/resource.c b/xserver/dix/resource.c
index 964f0b306..ad71b2437 100644
--- a/xserver/dix/resource.c
+++ b/xserver/dix/resource.c
@@ -510,7 +510,7 @@ CreateNewResourceType(DeleteType deleteFunc, const char *name)
if (next & lastResourceClass)
return 0;
- types = realloc(resourceTypes, (next + 1) * sizeof(*resourceTypes));
+ types = reallocarray(resourceTypes, next + 1, sizeof(*resourceTypes));
if (!types)
return 0;
@@ -600,6 +600,29 @@ CreateNewResourceClass(void)
static ClientResourceRec clientTable[MAXCLIENTS];
+static unsigned int
+ilog2(int val)
+{
+ int bits;
+
+ if (val <= 0)
+ return 0;
+ for (bits = 0; val != 0; bits++)
+ val >>= 1;
+ return bits - 1;
+}
+
+/*****************
+ * ResourceClientBits
+ * Returns the client bit offset in the client + resources ID field
+ *****************/
+
+unsigned int
+ResourceClientBits(void)
+{
+ return (ilog2(LimitClients));
+}
+
/*****************
* InitClientResources
* When a new client is created, call this to allocate space
@@ -834,10 +857,10 @@ RebuildTable(int client)
*/
j = 2 * clientTable[client].buckets;
- tails = malloc(j * sizeof(ResourcePtr *));
+ tails = xallocarray(j, sizeof(ResourcePtr *));
if (!tails)
return;
- resources = malloc(j * sizeof(ResourcePtr));
+ resources = xallocarray(j, sizeof(ResourcePtr));
if (!resources) {
free(tails);
return;
@@ -883,7 +906,7 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType)
int *eltptr;
int elements;
- if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) {
+ if (((cid = CLIENT_ID(id)) < LimitClients) && clientTable[cid].buckets) {
head = &clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
eltptr = &clientTable[cid].elements;
@@ -917,7 +940,7 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
ResourcePtr res;
ResourcePtr *prev, *head;
- if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) {
+ if (((cid = CLIENT_ID(id)) < LimitClients) && clientTable[cid].buckets) {
head = &clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
prev = head;
@@ -952,7 +975,7 @@ ChangeResourceValue(XID id, RESTYPE rtype, void *value)
int cid;
ResourcePtr res;
- if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) {
+ if (((cid = CLIENT_ID(id)) < LimitClients) && clientTable[cid].buckets) {
res = clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
for (; res; res = res->next)
@@ -1190,7 +1213,7 @@ dixLookupResourceByType(void **result, XID id, RESTYPE rtype,
if ((rtype & TypeMask) > lastResourceType)
return BadImplementation;
- if ((cid < MAXCLIENTS) && clientTable[cid].buckets) {
+ if ((cid < LimitClients) && clientTable[cid].buckets) {
res = clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
for (; res; res = res->next)
@@ -1223,7 +1246,7 @@ dixLookupResourceByClass(void **result, XID id, RESTYPE rclass,
*result = NULL;
- if ((cid < MAXCLIENTS) && clientTable[cid].buckets) {
+ if ((cid < LimitClients) && clientTable[cid].buckets) {
res = clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
for (; res; res = res->next)