util/idalloc: resize if ID is too large for reservation
authorMarek Olšák <marek.olsak@amd.com>
Wed, 30 Sep 2020 17:44:52 +0000 (13:44 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 6 Oct 2020 15:59:07 +0000 (15:59 +0000)
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7031>

src/util/u_idalloc.c

index b5d886d..9255faa 100644 (file)
@@ -103,7 +103,8 @@ util_idalloc_free(struct util_idalloc *buf, unsigned id)
 void
 util_idalloc_reserve(struct util_idalloc *buf, unsigned id)
 {
-   assert(id < buf->num_elements);
+   if (id >= buf->num_elements)
+      util_idalloc_resize(buf, id * 2);
    assert((buf->data[id / 32] & (1u << (id % 32))) == 0);
    buf->data[id / 32] |= 1u << (id % 32);
 }