--- embedaddon/sudo/plugins/sudoers/redblack.c 2012/02/21 16:23:02 1.1.1.1 +++ embedaddon/sudo/plugins/sudoers/redblack.c 2012/05/29 12:26:49 1.1.1.2 @@ -57,6 +57,7 @@ #include "missing.h" #include "alloc.h" +#include "sudo_debug.h" #include "redblack.h" static void rbrepair(struct rbtree *, struct rbnode *); @@ -90,6 +91,7 @@ struct rbtree * rbcreate(int (*compar)(const void *, const void*)) { struct rbtree *tree; + debug_decl(rbcreate, SUDO_DEBUG_RBTREE) tree = (struct rbtree *) emalloc(sizeof(*tree)); tree->compar = compar; @@ -110,7 +112,7 @@ rbcreate(int (*compar)(const void *, const void*)) tree->root.color = black; tree->root.data = NULL; - return tree; + debug_return_ptr(tree); } /* @@ -120,6 +122,7 @@ static void rotate_left(struct rbtree *tree, struct rbnode *node) { struct rbnode *child; + debug_decl(rotate_left, SUDO_DEBUG_RBTREE) child = node->right; node->right = child->left; @@ -134,6 +137,8 @@ rotate_left(struct rbtree *tree, struct rbnode *node) node->parent->right = child; child->left = node; node->parent = child; + + debug_return; } /* @@ -143,6 +148,7 @@ static void rotate_right(struct rbtree *tree, struct rbnode *node) { struct rbnode *child; + debug_decl(rotate_right, SUDO_DEBUG_RBTREE) child = node->left; node->left = child->right; @@ -157,6 +163,8 @@ rotate_right(struct rbtree *tree, struct rbnode *node) node->parent->right = child; child->right = node; node->parent = child; + + debug_return; } /* @@ -170,12 +178,13 @@ rbinsert(struct rbtree *tree, void *data) struct rbnode *node = rbfirst(tree); struct rbnode *parent = rbroot(tree); int res; + debug_decl(rbinsert, SUDO_DEBUG_RBTREE) /* Find correct insertion point. */ while (node != rbnil(tree)) { parent = node; if ((res = tree->compar(data, node->data)) == 0) - return node; + debug_return_ptr(node); node = res < 0 ? node->left : node->right; } @@ -249,7 +258,7 @@ rbinsert(struct rbtree *tree, void *data) } } rbfirst(tree)->color = black; /* first node is always black */ - return NULL; + debug_return_ptr(NULL); } /* @@ -261,13 +270,14 @@ rbfind(struct rbtree *tree, void *key) { struct rbnode *node = rbfirst(tree); int res; + debug_decl(rbfind, SUDO_DEBUG_RBTREE) while (node != rbnil(tree)) { if ((res = tree->compar(key, node->data)) == 0) - return node; + debug_return_ptr(node); node = res < 0 ? node->left : node->right; } - return NULL; + debug_return_ptr(NULL); } /* @@ -280,23 +290,24 @@ rbapply_node(struct rbtree *tree, struct rbnode *node, int (*func)(void *, void *), void *cookie, enum rbtraversal order) { int error; + debug_decl(rbapply_node, SUDO_DEBUG_RBTREE) if (node != rbnil(tree)) { if (order == preorder) if ((error = func(node->data, cookie)) != 0) - return error; + debug_return_int(error); if ((error = rbapply_node(tree, node->left, func, cookie, order)) != 0) - return error; + debug_return_int(error); if (order == inorder) if ((error = func(node->data, cookie)) != 0) - return error; + debug_return_int(error); if ((error = rbapply_node(tree, node->right, func, cookie, order)) != 0) - return error; + debug_return_int(error); if (order == postorder) if ((error = func(node->data, cookie)) != 0) - return error; + debug_return_int(error); } - return 0; + debug_return_int(0); } /* @@ -306,6 +317,7 @@ static struct rbnode * rbsuccessor(struct rbtree *tree, struct rbnode *node) { struct rbnode *succ; + debug_decl(rbsuccessor, SUDO_DEBUG_RBTREE) if ((succ = node->right) != rbnil(tree)) { while (succ->left != rbnil(tree)) @@ -317,7 +329,7 @@ rbsuccessor(struct rbtree *tree, struct rbnode *node) if (succ == rbroot(tree)) succ = rbnil(tree); } - return succ; + debug_return_ptr(succ); } /* @@ -326,6 +338,7 @@ rbsuccessor(struct rbtree *tree, struct rbnode *node) static void _rbdestroy(struct rbtree *tree, struct rbnode *node, void (*destroy)(void *)) { + debug_decl(_rbdestroy, SUDO_DEBUG_RBTREE) if (node != rbnil(tree)) { _rbdestroy(tree, node->left, destroy); _rbdestroy(tree, node->right, destroy); @@ -333,6 +346,7 @@ _rbdestroy(struct rbtree *tree, struct rbnode *node, v destroy(node->data); efree(node); } + debug_return; } /* @@ -342,8 +356,10 @@ _rbdestroy(struct rbtree *tree, struct rbnode *node, v void rbdestroy(struct rbtree *tree, void (*destroy)(void *)) { + debug_decl(rbdestroy, SUDO_DEBUG_RBTREE) _rbdestroy(tree, rbfirst(tree), destroy); efree(tree); + debug_return; } /* @@ -353,6 +369,7 @@ void *rbdelete(struct rbtree *tree, struct rbnode *z) { struct rbnode *x, *y; void *data = z->data; + debug_decl(rbdelete, SUDO_DEBUG_RBTREE) if (z->left == rbnil(tree) || z->right == rbnil(tree)) y = z; @@ -383,7 +400,7 @@ void *rbdelete(struct rbtree *tree, struct rbnode *z) } free(z); - return data; + debug_return_ptr(data); } /* @@ -394,6 +411,7 @@ static void rbrepair(struct rbtree *tree, struct rbnode *node) { struct rbnode *sibling; + debug_decl(rbrepair, SUDO_DEBUG_RBTREE) while (node->color == black && node != rbroot(tree)) { if (node == node->parent->left) { @@ -447,4 +465,6 @@ rbrepair(struct rbtree *tree, struct rbnode *node) } } node->color = black; + + debug_return; }