Skip to content

Commit

Permalink
Add runtime check on dict type member dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Harkrishn Patro <[email protected]>
  • Loading branch information
hpatro committed Jul 1, 2024
1 parent 4ca43ce commit 825c82f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ static dictEntry *dictGetNext(const dictEntry *de);
static dictEntry **dictGetNextRef(dictEntry *de);
static void dictSetNext(dictEntry *de, dictEntry *next);

/* -------------------------- Utility functions -------------------------------- */

/* Validates dict type members dependencies. */
static inline void validateDictType(dictType *type) {
if (type->embedded_entry) {
assert(type->embedKey);
assert(!type->keyDup);
assert(!type->keyDestructor);
} else {
assert(!type->embedKey);
}
}

/* -------------------------- hash functions -------------------------------- */

static uint8_t dict_hash_function_seed[16];
Expand Down Expand Up @@ -241,6 +254,7 @@ static void _dictReset(dict *d, int htidx) {

/* Create a new hash table */
dict *dictCreate(dictType *type) {
validateDictType(type);
size_t metasize = type->dictMetadataBytes ? type->dictMetadataBytes(NULL) : 0;
dict *d = zmalloc(sizeof(*d) + metasize);
if (metasize > 0) {
Expand Down

0 comments on commit 825c82f

Please sign in to comment.