]> git.sur5r.net Git - openldap/commitdiff
avl_delete...
authorHoward Chu <hyc@openldap.org>
Mon, 26 Sep 2005 08:57:19 +0000 (08:57 +0000)
committerHoward Chu <hyc@openldap.org>
Mon, 26 Sep 2005 08:57:19 +0000 (08:57 +0000)
libraries/liblutil/avl.c
libraries/liblutil/tavl.c

index e5a5153d08fc11ceee4b295075891c73f1b2b701..14b4c46fda702a0e3a02aa6b30c6ed66042d1716 100644 (file)
@@ -230,14 +230,13 @@ avl_delete( Avlnode **root, void* data, AVL_CMP fcmp )
                /* fix stack positions: old parent of p points to q */
                pptr[side] = q;
                if ( side ) {
-                       --side;
-                       r = pptr[side];
-                       r->avl_link[pdir[side]] = q;
+                       r = pptr[side-1];
+                       r->avl_link[pdir[side-1]] = q;
                } else {
                        *root = q;
                }
                /* new parent of p points to p */
-               if ( depth > 1 ) {
+               if ( depth-side > 1 ) {
                        r = pptr[depth-1];
                        r->avl_link[1] = p;
                } else {
@@ -246,7 +245,7 @@ avl_delete( Avlnode **root, void* data, AVL_CMP fcmp )
        }
 
        /* now <p> has at most one child, get it */
-       q = p->avl_link[0];
+       q = p->avl_link[0] ? p->avl_link[0] : p->avl_link[1];
 
        ber_memfree( p );
 
index 77069393aed91e494546a0bc2d57aac88329aeea..f588c71d8801b2e10de5e3f62f70ce1cb34bf54d 100644 (file)
@@ -244,14 +244,13 @@ tavl_delete( Avlnode **root, void* data, AVL_CMP fcmp )
                /* fix stack positions: old parent of p points to q */
                pptr[side] = q;
                if ( side ) {
-                       --side;
-                       r = pptr[side];
-                       r->avl_link[pdir[side]] = q;
+                       r = pptr[side-1];
+                       r->avl_link[pdir[side-1]] = q;
                } else {
                        *root = q;
                }
                /* new parent of p points to p */
-               if ( depth > 1 ) {
+               if ( depth-side > 1 ) {
                        r = pptr[depth-1];
                        r->avl_link[1] = p;
                } else {