]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix deletion from hash
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 14 Feb 2018 11:45:20 +0000 (11:45 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 14 Feb 2018 14:45:25 +0000 (14:45 +0000)
contrib/libucl/ucl_hash.c

index ce2a4fdb5adf480c7ccbd798a21abb3db75fc570..92c8b3933c06bff998afc1edee63d9769f06d1e0 100644 (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 --;
+                       }
                }
        }
 }