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>2012-10-22 11:57:21 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-10-22 11:57:21 +0400
commit30fd258a0b407419a369fbb2818c49df6b70968e (patch)
treefcc9c0f67ff0c6cba6181a4960536b6c08899741 /source/blender/blenlib/intern/BLI_heap.c
parentffd98941b5d6ef1ba8523f5c3c50bd1cf046a57f (diff)
fix for own error in BLI_heap_new_ex() when zero size is passed.
Diffstat (limited to 'source/blender/blenlib/intern/BLI_heap.c')
-rw-r--r--source/blender/blenlib/intern/BLI_heap.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c
index 3f88e336325..d3b1bdfa8fa 100644
--- a/source/blender/blenlib/intern/BLI_heap.c
+++ b/source/blender/blenlib/intern/BLI_heap.c
@@ -122,8 +122,8 @@ static void heap_up(Heap *heap, unsigned int i)
Heap *BLI_heap_new_ex(unsigned int tot_reserve)
{
Heap *heap = (Heap *)MEM_callocN(sizeof(Heap), __func__);
- heap->bufsize = tot_reserve;
- heap->tree = (HeapNode **)MEM_mallocN(tot_reserve * sizeof(HeapNode *), "BLIHeapTree");
+ heap->bufsize = MAX2(1, tot_reserve);
+ heap->tree = (HeapNode **)MEM_mallocN(heap->bufsize * sizeof(HeapNode *), "BLIHeapTree");
heap->arena = BLI_memarena_new(1 << 16, "heap arena");
return heap;
@@ -152,23 +152,17 @@ HeapNode *BLI_heap_insert(Heap *heap, float value, void *ptr)
HeapNode *node;
if ((heap->size + 1) > heap->bufsize) {
- unsigned int newsize = heap->bufsize * 2;
- HeapNode **newtree;
-
- newtree = (HeapNode **)MEM_mallocN(newsize * sizeof(*newtree), __func__);
- memcpy(newtree, heap->tree, sizeof(HeapNode *) * heap->size);
- MEM_freeN(heap->tree);
-
- heap->tree = newtree;
- heap->bufsize = newsize;
+ heap->bufsize = heap->bufsize * 2;
+ heap->tree = MEM_reallocN(heap->tree, heap->bufsize * sizeof(*heap->tree));
}
if (heap->freenodes) {
node = heap->freenodes;
heap->freenodes = (HeapNode *)(((HeapNode *)heap->freenodes)->ptr);
}
- else
+ else {
node = (HeapNode *)BLI_memarena_alloc(heap->arena, sizeof *node);
+ }
node->value = value;
node->ptr = ptr;