Browse Source

[Fix] Fix deletion from hash

tags/1.7.0
Vsevolod Stakhov 6 years ago
parent
commit
57747dfc45
1 changed files with 15 additions and 0 deletions
  1. 15
    0
      contrib/libucl/ucl_hash.c

+ 15
- 0
contrib/libucl/ucl_hash.c View File

@@ -368,6 +368,7 @@ ucl_hash_delete (ucl_hash_t* hashlin, const ucl_object_t *obj)
{
khiter_t k;
struct ucl_hash_elt *elt;
size_t i;

if (hashlin == NULL) {
return;
@@ -380,8 +381,15 @@ ucl_hash_delete (ucl_hash_t* hashlin, const ucl_object_t *obj)
k = kh_get (ucl_hash_caseless_node, h, obj);
if (k != kh_end (h)) {
elt = &kh_value (h, k);
i = elt->ar_idx;
kv_del (const ucl_object_t *, hashlin->ar, elt->ar_idx);
kh_del (ucl_hash_caseless_node, h, k);

/* Update subsequent elts */
for (; i < hashlin->ar.n; i ++) {
elt = &kh_value (h, i);
elt->ar_idx --;
}
}
}
else {
@@ -390,8 +398,15 @@ ucl_hash_delete (ucl_hash_t* hashlin, const ucl_object_t *obj)
k = kh_get (ucl_hash_node, h, obj);
if (k != kh_end (h)) {
elt = &kh_value (h, k);
i = elt->ar_idx;
kv_del (const ucl_object_t *, hashlin->ar, elt->ar_idx);
kh_del (ucl_hash_node, h, k);

/* Update subsequent elts */
for (; i < hashlin->ar.n; i ++) {
elt = &kh_value (h, i);
elt->ar_idx --;
}
}
}
}

Loading…
Cancel
Save