0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-10 05:08:42 +00:00

Extend remove_node() with deleting root node

This commit is contained in:
Igor Putovny 2023-09-21 13:33:17 +02:00
parent 26ac6dca5c
commit 7657d05592

View File

@ -95,9 +95,11 @@ static void
remove_node(struct trie_node *node) remove_node(struct trie_node *node)
{ {
assert(node != NULL); assert(node != NULL);
assert(node->parent != NULL);
assert(node->child[0] == NULL && node->child[1] == NULL); assert(node->child[0] == NULL && node->child[1] == NULL);
if (node->parent == NULL)
goto free_node;
if (node->parent->child[0] == node) if (node->parent->child[0] == node)
node->parent->child[0] = NULL; node->parent->child[0] = NULL;
else if (node->parent->child[1] == node) else if (node->parent->child[1] == node)
@ -105,7 +107,8 @@ remove_node(struct trie_node *node)
else else
bug("Invalid child pointer"); bug("Invalid child pointer");
sl_free(node); free_node:
sl_free(node);
} }
static void static void