From 1e3904677c8c66d8e2d29189273a81a6b5a47e38 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 26 Apr 2014 06:55:36 +1000 Subject: Avoid integer overflow in build_implicit_tree_helper --- source/blender/blenlib/intern/BLI_kdopbvh.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source') diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index 6fdfac2e1cb..6b1fbe855a1 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -617,9 +617,7 @@ static void build_implicit_tree_helper(BVHTree *tree, BVHBuildHelper *data) data->branches_on_level[0] = 1; - /* We could stop the loop first (but I am lazy to find out when) */ - /* note: this often causes integer overflow, may be worth avoiding? - campbell */ - for (depth = 1; depth < 32; depth++) { + for (depth = 1; (depth < 32) && data->leafs_per_child[depth - 1]; depth++) { data->branches_on_level[depth] = data->branches_on_level[depth - 1] * data->tree_type; data->leafs_per_child[depth] = data->leafs_per_child[depth - 1] / data->tree_type; } -- cgit v1.2.3