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

2017-11-27 Thread Lionel Landwerlin
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 
---
 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

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


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

2017-11-27 Thread Ian Romanick
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 
> ---
>  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++;
> 

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev