]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
hash: add asserts to help detect bad usage
authorDaniel Stenberg <daniel@haxx.se>
Wed, 8 Dec 2021 12:22:44 +0000 (13:22 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 9 Dec 2021 09:18:41 +0000 (10:18 +0100)
For example trying to add entries after the hash has been "cleaned up"

Closes #8115

lib/hash.c

index 12e7aa5f278a2198dac6ec695afbd0a0952ed071..f04c462840d15792a67a97324e46f8de659dc3e8 100644 (file)
@@ -110,7 +110,9 @@ Curl_hash_add(struct Curl_hash *h, void *key, size_t key_len, void *p)
 {
   struct Curl_hash_element  *he;
   struct Curl_llist_element *le;
-  struct Curl_llist *l = FETCH_LIST(h, key, key_len);
+  struct Curl_llist *l;
+  DEBUGASSERT(h->slots);
+  l = FETCH_LIST(h, key, key_len);
 
   for(le = l->head; le; le = le->next) {
     he = (struct Curl_hash_element *) le->ptr;
@@ -139,7 +141,9 @@ Curl_hash_add(struct Curl_hash *h, void *key, size_t key_len, void *p)
 int Curl_hash_delete(struct Curl_hash *h, void *key, size_t key_len)
 {
   struct Curl_llist_element *le;
-  struct Curl_llist *l = FETCH_LIST(h, key, key_len);
+  struct Curl_llist *l;
+  DEBUGASSERT(h->slots);
+  l = FETCH_LIST(h, key, key_len);
 
   for(le = l->head; le; le = le->next) {
     struct Curl_hash_element *he = le->ptr;
@@ -163,6 +167,7 @@ Curl_hash_pick(struct Curl_hash *h, void *key, size_t key_len)
   struct Curl_llist *l;
 
   if(h) {
+    DEBUGASSERT(h->slots);
     l = FETCH_LIST(h, key, key_len);
     for(le = l->head; le; le = le->next) {
       struct Curl_hash_element *he = le->ptr;