]> git.sur5r.net Git - openldap/blobdiff - libraries/liblutil/avl.c
cleanup
[openldap] / libraries / liblutil / avl.c
index e5a5153d08fc11ceee4b295075891c73f1b2b701..4d6d74431ba27c12b1a26b6ae895d8645dc3aefe 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Copyright 1998-2006 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -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 );