From: Timo Kokkonen Date: Sat, 24 Apr 2010 10:59:14 +0000 (+0300) Subject: quadtree_add: Zero child pointers when a new node is added X-Git-Url: http://git.itanic.dy.fi/?p=sdl-planets;a=commitdiff_plain;h=29fe1630973392185731f4289537e29365d315fc quadtree_add: Zero child pointers when a new node is added Since we don't support adding an entire subtree, it is better to zero out the child pointers to ensure there are no leftover child nodes that might corrupt the tree integrity. Signed-off-by: Timo Kokkonen --- diff --git a/quadtree.c b/quadtree.c index de59a2f..a331539 100644 --- a/quadtree.c +++ b/quadtree.c @@ -123,7 +123,7 @@ static void validate_tree(const struct quadtree *node) struct quadtree *quadtree_add(struct quadtree *parent, struct quadtree *new, struct quadtree_ops *ops) { - int ret; + int ret, i; if (parent == new) trap(); @@ -141,6 +141,8 @@ struct quadtree *quadtree_add(struct quadtree *parent, struct quadtree *new, parent->child[ret] = new; new->parent = parent; + for (i = 0; i < 4; i++) + new->child[i] = 0; if (debug) { printf("adding node %p to parent %p\n", new, parent);