From 29fe1630973392185731f4289537e29365d315fc Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Sat, 24 Apr 2010 13:59:14 +0300 Subject: [PATCH] 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 --- quadtree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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); -- 2.44.0