]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/typesafe.c
Merge pull request #5104 from opensourcerouting/route-map-nbv2
[mirror_frr.git] / lib / typesafe.c
index f2ca67b7c66b690f5f10c0b66ae0d9cbfa595184..6635cf75067c5c78e01a042d94f0e0203a7a1f89 100644 (file)
@@ -341,13 +341,14 @@ struct sskip_item *typesafe_skiplist_find_lt(struct sskip_head *head,
        return best;
 }
 
-void typesafe_skiplist_del(struct sskip_head *head, struct sskip_item *item,
-               int (*cmpfn)(const struct sskip_item *a,
-                               const struct sskip_item *b))
+struct sskip_item *typesafe_skiplist_del(
+       struct sskip_head *head, struct sskip_item *item,
+       int (*cmpfn)(const struct sskip_item *a, const struct sskip_item *b))
 {
        size_t level = SKIPLIST_MAXDEPTH;
        struct sskip_item *prev = &head->hitem, *next;
        int cmpval;
+       bool found = false;
 
        while (level) {
                next = sl_level_get(prev, level - 1);
@@ -359,6 +360,7 @@ void typesafe_skiplist_del(struct sskip_head *head, struct sskip_item *item,
                        sl_level_set(prev, level - 1,
                                sl_level_get(item, level - 1));
                        level--;
+                       found = true;
                        continue;
                }
                cmpval = cmpfn(next, item);
@@ -369,6 +371,9 @@ void typesafe_skiplist_del(struct sskip_head *head, struct sskip_item *item,
                level--;
        }
 
+       if (!found)
+               return NULL;
+
        /* TBD: assert when trying to remove non-existing item? */
        head->count--;
 
@@ -379,6 +384,8 @@ void typesafe_skiplist_del(struct sskip_head *head, struct sskip_item *item,
                XFREE(MTYPE_SKIPLIST_OFLOW, oflow);
        }
        memset(item, 0, sizeof(*item));
+
+       return item;
 }
 
 struct sskip_item *typesafe_skiplist_pop(struct sskip_head *head)
@@ -466,7 +473,7 @@ void typesafe_heap_resize(struct heap_head *head, bool grow)
        newsize &= ~(HEAP_NARY - 1);
        if (newsize == head->arraysz)
                return;
-       
+
        head->array = XREALLOC(MTYPE_HEAP_ARRAY, head->array,
                               newsize * sizeof(struct heap_item *));
        head->arraysz = newsize;