fix(hmp): prevent crash when passing anything non-existent to hmp funcs

This commit is contained in:
2025-09-05 23:51:16 -04:00
parent f4d09675af
commit 47614633c3

12
ds.c
View File

@@ -171,6 +171,10 @@ ds_hmp_t
{
ds_hmp_t *hmp;
if (!data_len) {
return NULL;
}
hmp = calloc(1, sizeof(ds_hmp_t));
hmp->data_len = data_len;
hmp->data = calloc(data_len, sizeof(ds_sll_t **));
@@ -255,6 +259,10 @@ void
ds_sll_t *cur, *ll;
unsigned hash_pos;
if (!hmp || !key) {
return NULL;
}
hash_pos = _ds_hmp_gen_hash(key) % hmp->data_len;
ll = hmp->data[hash_pos];
if (!ll) {
@@ -279,6 +287,10 @@ void
ds_sll_t *ll, *cur;
_ds_hmp_kv_t *kv;
if (!hmp || !key) {
return NULL;
}
hash_pos = _ds_hmp_gen_hash(key) % hmp->data_len;
ll = hmp->data[hash_pos];
if (!ll) {