fix(hmp): prevent crash when passing anything non-existent to hmp funcs
This commit is contained in:
parent
f4d09675af
commit
47614633c3
1 changed files with 12 additions and 0 deletions
12
ds.c
12
ds.c
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue