mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-09 08:58:02 +02:00
util: fix possible null pointer usage
found by the clang static analyzer
This commit is contained in:
parent
21cce6afb0
commit
4873031e29
4 changed files with 46 additions and 11 deletions
|
|
@ -137,6 +137,8 @@ util_cache_set(struct util_cache *cache,
|
|||
struct util_cache_entry *entry;
|
||||
|
||||
assert(cache);
|
||||
if (!cache)
|
||||
return;
|
||||
|
||||
entry = util_cache_entry_get(cache, key);
|
||||
util_cache_entry_destroy(cache, entry);
|
||||
|
|
@ -158,6 +160,8 @@ util_cache_get(struct util_cache *cache,
|
|||
struct util_cache_entry *entry;
|
||||
|
||||
assert(cache);
|
||||
if (!cache)
|
||||
return NULL;
|
||||
|
||||
entry = util_cache_entry_get(cache, key);
|
||||
if(!entry->key && !entry->value)
|
||||
|
|
@ -176,7 +180,9 @@ util_cache_clear(struct util_cache *cache)
|
|||
uint32_t i;
|
||||
|
||||
assert(cache);
|
||||
|
||||
if (!cache)
|
||||
return;
|
||||
|
||||
for(i = 0; i < cache->size; ++i)
|
||||
util_cache_entry_destroy(cache, &cache->entries[i]);
|
||||
}
|
||||
|
|
@ -186,6 +192,8 @@ void
|
|||
util_cache_destroy(struct util_cache *cache)
|
||||
{
|
||||
assert(cache);
|
||||
if (!cache)
|
||||
return;
|
||||
|
||||
#ifdef DEBUG
|
||||
if(cache->count >= 20*cache->size) {
|
||||
|
|
|
|||
|
|
@ -87,6 +87,8 @@ handle_table_set_destroy(struct handle_table *ht,
|
|||
void (*destroy)(void *object))
|
||||
{
|
||||
assert(ht);
|
||||
if (!ht)
|
||||
return;
|
||||
ht->destroy = destroy;
|
||||
}
|
||||
|
||||
|
|
@ -155,7 +157,7 @@ handle_table_add(struct handle_table *ht,
|
|||
|
||||
assert(ht);
|
||||
assert(object);
|
||||
if(!object)
|
||||
if(!object || !ht)
|
||||
return 0;
|
||||
|
||||
/* linear search for an empty handle */
|
||||
|
|
@ -193,7 +195,7 @@ handle_table_set(struct handle_table *ht,
|
|||
|
||||
assert(ht);
|
||||
assert(handle);
|
||||
if(!handle)
|
||||
if(!handle || !ht)
|
||||
return 0;
|
||||
|
||||
assert(object);
|
||||
|
|
@ -222,7 +224,7 @@ handle_table_get(struct handle_table *ht,
|
|||
|
||||
assert(ht);
|
||||
assert(handle);
|
||||
if(!handle || handle > ht->size)
|
||||
if(!handle || !ht || handle > ht->size)
|
||||
return NULL;
|
||||
|
||||
object = ht->objects[handle - 1];
|
||||
|
|
@ -240,7 +242,7 @@ handle_table_remove(struct handle_table *ht,
|
|||
|
||||
assert(ht);
|
||||
assert(handle);
|
||||
if(!handle || handle > ht->size)
|
||||
if(!handle || !ht || handle > ht->size)
|
||||
return;
|
||||
|
||||
index = handle - 1;
|
||||
|
|
@ -283,6 +285,9 @@ handle_table_destroy(struct handle_table *ht)
|
|||
unsigned index;
|
||||
assert(ht);
|
||||
|
||||
if (!ht)
|
||||
return;
|
||||
|
||||
if(ht->destroy)
|
||||
for(index = 0; index < ht->size; ++index)
|
||||
handle_table_clear(ht, index);
|
||||
|
|
|
|||
|
|
@ -148,6 +148,8 @@ hash_table_set(struct hash_table *ht,
|
|||
struct cso_hash_iter iter;
|
||||
|
||||
assert(ht);
|
||||
if (!ht)
|
||||
return PIPE_ERROR_BAD_INPUT;
|
||||
|
||||
key_hash = ht->hash(key);
|
||||
|
||||
|
|
@ -183,6 +185,8 @@ hash_table_get(struct hash_table *ht,
|
|||
struct hash_table_item *item;
|
||||
|
||||
assert(ht);
|
||||
if (!ht)
|
||||
return NULL;
|
||||
|
||||
key_hash = ht->hash(key);
|
||||
|
||||
|
|
@ -203,6 +207,8 @@ hash_table_remove(struct hash_table *ht,
|
|||
struct hash_table_item *item;
|
||||
|
||||
assert(ht);
|
||||
if (!ht)
|
||||
return;
|
||||
|
||||
key_hash = ht->hash(key);
|
||||
|
||||
|
|
@ -225,7 +231,9 @@ hash_table_clear(struct hash_table *ht)
|
|||
struct hash_table_item *item;
|
||||
|
||||
assert(ht);
|
||||
|
||||
if (!ht)
|
||||
return;
|
||||
|
||||
iter = cso_hash_first_node(ht->cso);
|
||||
while (!cso_hash_iter_is_null(iter)) {
|
||||
item = (struct hash_table_item *)cso_hash_take(ht->cso, cso_hash_iter_key(iter));
|
||||
|
|
@ -243,9 +251,11 @@ hash_table_foreach(struct hash_table *ht,
|
|||
struct cso_hash_iter iter;
|
||||
struct hash_table_item *item;
|
||||
enum pipe_error result;
|
||||
|
||||
|
||||
assert(ht);
|
||||
|
||||
if (!ht)
|
||||
return PIPE_ERROR_BAD_INPUT;
|
||||
|
||||
iter = cso_hash_first_node(ht->cso);
|
||||
while (!cso_hash_iter_is_null(iter)) {
|
||||
item = (struct hash_table_item *)cso_hash_iter_data(iter);
|
||||
|
|
@ -264,9 +274,11 @@ hash_table_destroy(struct hash_table *ht)
|
|||
{
|
||||
struct cso_hash_iter iter;
|
||||
struct hash_table_item *item;
|
||||
|
||||
|
||||
assert(ht);
|
||||
|
||||
if (!ht)
|
||||
return;
|
||||
|
||||
iter = cso_hash_first_node(ht->cso);
|
||||
while (!cso_hash_iter_is_null(iter)) {
|
||||
item = (struct hash_table_item *)cso_hash_iter_data(iter);
|
||||
|
|
|
|||
|
|
@ -194,6 +194,8 @@ util_keymap_insert(struct keymap *map, const void *key,
|
|||
struct cso_hash_iter iter;
|
||||
|
||||
assert(map);
|
||||
if (!map)
|
||||
return FALSE;
|
||||
|
||||
key_hash = hash(key, map->key_size);
|
||||
|
||||
|
|
@ -234,6 +236,8 @@ util_keymap_lookup(const struct keymap *map, const void *key)
|
|||
struct keymap_item *item;
|
||||
|
||||
assert(map);
|
||||
if (!map)
|
||||
return NULL;
|
||||
|
||||
key_hash = hash(key, map->key_size);
|
||||
|
||||
|
|
@ -258,6 +262,8 @@ util_keymap_remove(struct keymap *map, const void *key, void *user)
|
|||
struct keymap_item *item;
|
||||
|
||||
assert(map);
|
||||
if (!map)
|
||||
return;
|
||||
|
||||
key_hash = hash(key, map->key_size);
|
||||
|
||||
|
|
@ -267,6 +273,8 @@ util_keymap_remove(struct keymap *map, const void *key, void *user)
|
|||
|
||||
item = hash_table_item(iter);
|
||||
assert(item);
|
||||
if (!item)
|
||||
return;
|
||||
map->delete_func(map, item->key, item->value, user);
|
||||
FREE(item->key);
|
||||
FREE(item);
|
||||
|
|
@ -288,7 +296,9 @@ util_keymap_remove_all(struct keymap *map, void *user)
|
|||
struct keymap_item *item;
|
||||
|
||||
assert(map);
|
||||
|
||||
if (!map)
|
||||
return;
|
||||
|
||||
iter = cso_hash_first_node(map->cso);
|
||||
while (!cso_hash_iter_is_null(iter)) {
|
||||
item = (struct keymap_item *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue