X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Fliblutil%2Ftavl.c;h=f1a8f71967fa423ab578cfddfba47bf7536fcfa1;hb=34249c08a5c15ebf15f78570ca61e6acad94dc22;hp=deecd6add368bd0d7b85317bdd9126aa9d771771;hpb=da6d9eb0463255782f3fa70c61fd958d94c048cf;p=openldap
diff --git a/libraries/liblutil/tavl.c b/libraries/liblutil/tavl.c
index deecd6add3..f1a8f71967 100644
--- a/libraries/liblutil/tavl.c
+++ b/libraries/liblutil/tavl.c
@@ -2,7 +2,7 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software .
*
- * Copyright 2005-2007 The OpenLDAP Foundation.
+ * Copyright 2005-2010 The OpenLDAP Foundation.
* Portions Copyright (c) 2005 by Howard Chu, Symas Corp.
* All rights reserved.
*
@@ -21,6 +21,7 @@
#include "portable.h"
+#include
#include
#include
@@ -35,6 +36,9 @@
#define AVL_INTERNAL
#include "avl.h"
+/* Maximum tree depth this host's address space could support */
+#define MAX_TREE_DEPTH (sizeof(void *) * CHAR_BIT)
+
static const int avl_bfs[] = {LH, RH};
/*
@@ -189,8 +193,8 @@ tavl_delete( Avlnode **root, void* data, AVL_CMP fcmp )
int side, side_bf, shorter, nside = -1;
/* parent stack */
- Avlnode *pptr[sizeof(void *)*8];
- unsigned char pdir[sizeof(void *)*8];
+ Avlnode *pptr[MAX_TREE_DEPTH];
+ unsigned char pdir[MAX_TREE_DEPTH];
int depth = 0;
if ( *root == NULL )
@@ -448,13 +452,13 @@ tavl_free( Avlnode *root, AVL_FREE dfree )
/*
* tavl_find2 - returns Avlnode instead of data pointer.
* tavl_find3 - as above, but returns Avlnode even if no match is found.
- * also return the last comparison result in ret.
+ * also set *ret = last comparison result, or -1 if root == NULL.
*/
Avlnode *
tavl_find3( Avlnode *root, const void *data, AVL_CMP fcmp, int *ret )
{
- int cmp, dir;
- Avlnode *prev;
+ int cmp = -1, dir;
+ Avlnode *prev = root;
while ( root != 0 && (cmp = (*fcmp)( data, root->avl_data )) != 0 ) {
prev = root;