]> git.itanic.dy.fi Git - sdl-planets/commitdiff
quadtree_add: Zero child pointers when a new node is added
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 24 Apr 2010 10:59:14 +0000 (13:59 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 24 Apr 2010 10:59:14 +0000 (13:59 +0300)
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 <kaapeli@itanic.dy.fi>
quadtree.c

index de59a2f61c6ead0b40b77b8ece67ac89fe23c956..a3315392f3ae3e9b669401946622cd66c5968e65 100644 (file)
@@ -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);