aboutsummaryrefslogtreecommitdiffstats
path: root/src/util/hash_table.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2019-06-05 17:30:47 -0500
committerJason Ekstrand <[email protected]>2019-06-06 00:27:53 +0000
commitb38dab101ca7e0896255dccbd85fd510c47d84d1 (patch)
treebc79f13b3a1970ee326f9f78741cc5015c95bc02 /src/util/hash_table.c
parent8306dabc03c9a030cacd078b56446e6548224a23 (diff)
util/hash_table: Assert that keys are not reserved pointers
If we insert a NULL key, it will appear to succeed but will mess up entry counting. Similar errors can occur if someone accidentally inserts the deleted key. The later is highly unlikely but technically possible so we should guard against it too. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Caio Marcelo de Oliveira Filho <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/util/hash_table.c')
-rw-r--r--src/util/hash_table.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/util/hash_table.c b/src/util/hash_table.c
index 74d03aa60fb..a764fabbf05 100644
--- a/src/util/hash_table.c
+++ b/src/util/hash_table.c
@@ -98,6 +98,12 @@ static const struct {
ENTRY(2147483648ul, 2362232233ul, 2362232231ul )
};
+static inline bool
+key_pointer_is_reserved(const struct hash_table *ht, const void *key)
+{
+ return key == NULL || key == ht->deleted_key;
+}
+
static int
entry_is_free(const struct hash_entry *entry)
{
@@ -250,6 +256,8 @@ _mesa_hash_table_set_deleted_key(struct hash_table *ht, const void *deleted_key)
static struct hash_entry *
hash_table_search(struct hash_table *ht, uint32_t hash, const void *key)
{
+ assert(!key_pointer_is_reserved(ht, key));
+
uint32_t size = ht->size;
uint32_t start_hash_address = util_fast_urem32(hash, size, ht->size_magic);
uint32_t double_hash = 1 + util_fast_urem32(hash, ht->rehash,
@@ -366,7 +374,7 @@ hash_table_insert(struct hash_table *ht, uint32_t hash,
{
struct hash_entry *available_entry = NULL;
- assert(key != NULL);
+ assert(!key_pointer_is_reserved(ht, key));
if (ht->entries >= ht->max_entries) {
_mesa_hash_table_rehash(ht, ht->size_index + 1);