diff options
author | Eric Anholt <eric@anholt.net> | 2017-12-01 14:22:38 -0800 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2017-12-01 14:26:43 -0800 |
commit | a88e17d31d51054ff3232eacbce2e8361a46dc8b (patch) | |
tree | c532462deaa5f531e093050652dd1e0b7142728a | |
parent | 6d12ab14d4e68e0100ec10735c1e2941fcfd61dd (diff) |
Add asserts that the user doesn't try to add the empty or deleted values.
-rw-r--r-- | hash_table.c | 8 | ||||
-rw-r--r-- | set.c | 8 |
2 files changed, 16 insertions, 0 deletions
diff --git a/hash_table.c b/hash_table.c index 8390472..95f5bd3 100644 --- a/hash_table.c +++ b/hash_table.c @@ -32,6 +32,7 @@ * Keith Packard <keithp@keithp.com> */ +#include <assert.h> #include <stdlib.h> #include "hash_table.h" @@ -244,6 +245,13 @@ hash_table_insert(struct hash_table *ht, const void *key, void *data) { uint32_t hash = ht->hash_function(key); + /* Make sure nobody tries to add one of the magic values as a + * key. If you need to do so, either do so in a wrapper, or + * store keys with the magic values separately in the struct + * hash_table. + */ + assert(key != NULL); + return hash_table_insert_pre_hashed(ht, hash, key, data); } @@ -32,6 +32,7 @@ * Keith Packard <keithp@keithp.com> */ +#include <assert.h> #include <stdlib.h> #include "set.h" @@ -258,6 +259,13 @@ set_add(struct set *set, const void *key) { uint32_t hash = set->hash_function(key); + /* Make sure nobody tries to add one of the magic values as a + * key. If you need to do so, either do so in a wrapper, or + * store keys with the magic values separately in the struct + * set. + */ + assert(key != NULL); + return set_add_pre_hashed(set, hash, key); } |