X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Favl_tree.c;h=f1645d52da71c71a7f9e8d66cc2e7f80125819ef;hp=a8bf5d5f733c99863c31cdcd9e19bdf86a0c8fca;hb=dc6c113176697aafb013feda87af973d80349585;hpb=68f4ca711593416d0defd81199b176ba604c6cb1 diff --git a/src/avl_tree.c b/src/avl_tree.c index a8bf5d5f..f1645d52 100644 --- a/src/avl_tree.c +++ b/src/avl_tree.c @@ -2,7 +2,7 @@ avl_tree.c -- avl_ tree and linked list convenience Copyright (C) 1998 Michael H. Buselli 2000-2005 Ivo Timmermans, - 2000-2006 Guus Sliepen + 2000-2014 Guus Sliepen 2000-2005 Wessel Dankers This program is free software; you can redistribute it and/or modify @@ -123,8 +123,6 @@ static void avl_rebalance(avl_tree_t *tree, avl_node_t *node) avl_node_t *parent; avl_node_t **superparent; - parent = node; - while(node) { parent = node->parent; @@ -168,14 +166,12 @@ static void avl_rebalance(avl_tree_t *tree, avl_node_t *node) child->right->parent = child; gchild->right = node; - if(gchild->right) - gchild->right->parent = gchild; + gchild->right->parent = gchild; gchild->left = child; - if(gchild->left) - gchild->left->parent = gchild; - *superparent = gchild; + gchild->left->parent = gchild; + *superparent = gchild; gchild->parent = parent; #ifdef AVL_COUNT node->count = AVL_CALC_COUNT(node); @@ -224,12 +220,10 @@ static void avl_rebalance(avl_tree_t *tree, avl_node_t *node) child->left->parent = child; gchild->left = node; - if(gchild->left) - gchild->left->parent = gchild; + gchild->left->parent = gchild; gchild->right = child; - if(gchild->right) - gchild->right->parent = gchild; + gchild->right->parent = gchild; *superparent = gchild; gchild->parent = parent; @@ -600,6 +594,8 @@ void avl_unlink_node(avl_tree_t *tree, avl_node_t *node) balnode = parent; } else { subst = node->prev; + if(!subst) // This only happens if node is not actually in a tree at all. + abort(); if(subst == left) { balnode = subst;