[Mesa-dev] [PATCH] util: hash_table: move NULL assert to string hashing function

Lionel Landwerlin lionel.g.landwerlin at intel.com
Mon Nov 27 16:27:38 UTC 2017


Hash maps might use pointer keys (which people surely might want to
use to hash values) in which case a 0 value is perfectly acceptable.
It's only if the hash function needs to deference the pointer that we
want to be sure it's not NULL.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
---
 src/util/hash_table.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/util/hash_table.c b/src/util/hash_table.c
index b7421a0144c..8a4de565fcc 100644
--- a/src/util/hash_table.c
+++ b/src/util/hash_table.c
@@ -296,8 +296,6 @@ hash_table_insert(struct hash_table *ht, uint32_t hash,
    uint32_t start_hash_address, hash_address;
    struct hash_entry *available_entry = NULL;
 
-   assert(key != NULL);
-
    if (ht->entries >= ht->max_entries) {
       _mesa_hash_table_rehash(ht, ht->size_index + 1);
    } else if (ht->deleted_entries + ht->entries >= ht->max_entries) {
@@ -481,6 +479,8 @@ _mesa_hash_string(const void *_key)
    uint32_t hash = _mesa_fnv32_1a_offset_bias;
    const char *key = _key;
 
+   assert(key != NULL);
+
    while (*key != 0) {
       hash = _mesa_fnv32_1a_accumulate(hash, *key);
       key++;
-- 
2.15.0



More information about the mesa-dev mailing list