summaryrefslogtreecommitdiff
path: root/usual/heap.c
diff options
context:
space:
mode:
authorMarko Kreen2010-11-04 12:04:07 +0000
committerMarko Kreen2010-11-04 12:04:07 +0000
commitad5673f3e809df84546a770343051cc3d800a97b (patch)
tree6f4832a772f1be6cee81eba56ab9d7c8edac270d /usual/heap.c
parentf302d46bd2cb10ca97749c204bcc64d6fb78ef50 (diff)
heap: fix few conversion bugs
Diffstat (limited to 'usual/heap.c')
-rw-r--r--usual/heap.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/usual/heap.c b/usual/heap.c
index 27b807b..c84679a 100644
--- a/usual/heap.c
+++ b/usual/heap.c
@@ -115,7 +115,7 @@ struct Heap *heap_create(heap_is_better_f is_better_cb, heap_save_pos_f save_pos
{
struct Heap *h;
- h = cx_alloc0(cx, sizeof(*cx));
+ h = cx_alloc0(cx, sizeof(*h));
if (!h)
return NULL;
@@ -146,7 +146,7 @@ bool heap_reserve(struct Heap *h, unsigned extra)
if (newalloc < h->used + extra)
newalloc = h->used + extra;
- tmp = realloc(h->data, newalloc * sizeof(void *));
+ tmp = cx_realloc(h->cx, h->data, newalloc * sizeof(void *));
if (!tmp)
return false;
h->data = tmp;
@@ -185,11 +185,11 @@ void *heap_remove(struct Heap *h, unsigned pos)
obj = h->data[pos];
last = --h->used;
- _heap_set(h, pos, h->data[last]);
+ if (pos < last) {
+ _heap_set(h, pos, h->data[last]);
+ rebalance(h, pos);
+ }
h->data[last] = NULL;
-
- rebalance(h, pos);
-
return obj;
}