[Mesa-dev] [PATCH 05/10] mesa: Add missing null checks into prog_hash_table.c
Juha-Pekka Heikkila
juhapekka.heikkila at gmail.com
Mon Feb 17 08:21:28 PST 2014
Check calloc return values in hash_table_insert() and
hash_table_replace()
Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
---
src/mesa/program/prog_hash_table.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/mesa/program/prog_hash_table.c b/src/mesa/program/prog_hash_table.c
index f45ed46..e62ad6f 100644
--- a/src/mesa/program/prog_hash_table.c
+++ b/src/mesa/program/prog_hash_table.c
@@ -143,10 +143,12 @@ hash_table_insert(struct hash_table *ht, void *data, const void *key)
node = calloc(1, sizeof(*node));
- node->data = data;
- node->key = key;
+ if (node != NULL) {
+ node->data = data;
+ node->key = key;
- insert_at_head(& ht->buckets[bucket], & node->link);
+ insert_at_head(& ht->buckets[bucket], & node->link);
+ }
}
bool
@@ -168,10 +170,12 @@ hash_table_replace(struct hash_table *ht, void *data, const void *key)
hn = calloc(1, sizeof(*hn));
- hn->data = data;
- hn->key = key;
+ if (hn != NULL) {
+ hn->data = data;
+ hn->key = key;
- insert_at_head(& ht->buckets[bucket], & hn->link);
+ insert_at_head(& ht->buckets[bucket], & hn->link);
+ }
return false;
}
--
1.8.1.2
More information about the mesa-dev
mailing list