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

Ian Romanick idr at freedesktop.org
Mon Nov 27 21:05:07 UTC 2017


On 11/27/2017 08:27 AM, Lionel Landwerlin wrote:
> 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);
> +

Should probably also add this check to _mesa_fnv32_1a_accumulate_block
or _mesa_hash_data too.

>     while (*key != 0) {
>        hash = _mesa_fnv32_1a_accumulate(hash, *key);
>        key++;
> 



More information about the mesa-dev mailing list