hash: add asserts to help detect bad usage

For example trying to add entries after the hash has been "cleaned up"

Closes #8115
This commit is contained in:
Daniel Stenberg 2021-12-08 13:22:44 +01:00
parent f443834c7a
commit 8d8f384f32
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View 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;