Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-09-11 06:34:30 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-09-11 06:47:52 +0400
commitbae66459dffb75e660b375cf8e6fff5d8b9c9b73 (patch)
tree009b220459009653887969721573cc4756379052 /source/blender
parent229c2c14f796b9d446301d9b0b8091c5e8a4f2ab (diff)
Fix crash in BLI_kdtree_range_search
Called memcpy with a NULL pointer, causing the following NULL check to get optimized away.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenlib/intern/BLI_kdtree.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/source/blender/blenlib/intern/BLI_kdtree.c b/source/blender/blenlib/intern/BLI_kdtree.c
index 082a54a5774..bf470d88578 100644
--- a/source/blender/blenlib/intern/BLI_kdtree.c
+++ b/source/blender/blenlib/intern/BLI_kdtree.c
@@ -406,20 +406,22 @@ static int range_compare(const void *a, const void *b)
else
return 0;
}
-static void add_in_range(KDTreeNearest **ptn, unsigned int found, unsigned int *totfoundstack, int index, float dist, float *co)
+static void add_in_range(
+ KDTreeNearest **r_foundstack,
+ unsigned int *r_foundstack_tot_alloc,
+ unsigned int found,
+ const int index, const float dist, const float *co)
{
KDTreeNearest *to;
- if (found >= *totfoundstack) {
- KDTreeNearest *temp = MEM_mallocN((*totfoundstack + KD_FOUND_ALLOC_INC) * sizeof(KDTreeNode), "KDTree.treefoundstack");
- memcpy(temp, *ptn, *totfoundstack * sizeof(KDTreeNearest));
- if (*ptn)
- MEM_freeN(*ptn);
- *ptn = temp;
- *totfoundstack += KD_FOUND_ALLOC_INC;
+ if (UNLIKELY(found >= *r_foundstack_tot_alloc)) {
+ *r_foundstack = MEM_reallocN_id(
+ *r_foundstack,
+ (*r_foundstack_tot_alloc += KD_FOUND_ALLOC_INC) * sizeof(KDTreeNode),
+ __func__);
}
- to = (*ptn) + found;
+ to = (*r_foundstack) + found;
to->index = index;
to->dist = sqrtf(dist);
@@ -464,7 +466,7 @@ int BLI_kdtree_range_search__normal(
else {
dist2 = squared_distance(root->co, co, nor);
if (dist2 <= range2)
- add_in_range(&foundstack, found++, &totfoundstack, root->index, dist2, root->co);
+ add_in_range(&foundstack, &totfoundstack, found++, root->index, dist2, root->co);
if (root->left)
stack[cur++] = root->left;
@@ -486,7 +488,7 @@ int BLI_kdtree_range_search__normal(
else {
dist2 = squared_distance(node->co, co, nor);
if (dist2 <= range2)
- add_in_range(&foundstack, found++, &totfoundstack, node->index, dist2, node->co);
+ add_in_range(&foundstack, &totfoundstack, found++, node->index, dist2, node->co);
if (node->left)
stack[cur++] = node->left;