summaryrefslogtreecommitdiff
path: root/src/common/heap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/heap.c')
-rw-r--r--src/common/heap.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/common/heap.c b/src/common/heap.c
index 27b82da..c8c7921 100644
--- a/src/common/heap.c
+++ b/src/common/heap.c
@@ -37,6 +37,7 @@
* ------
***/
+#include <config.h>
#include "heap.h"
#include <string.h>
#include <stdlib.h>
@@ -60,7 +61,7 @@ int heap_init(struct heap *h, int (*cmp)(void *, void *), int init_size)
h->data = malloc((isize + 1) * sizeof(heap_val_t)); /* Temp element unused. */
return h->data ? 1 : 0;
-};
+}
static inline void _heap_bubble_down(struct heap *h, int e)
{
@@ -86,7 +87,7 @@ static inline void _heap_bubble_up(struct heap *h, int e)
heap_swap(HELEMENT(h,e),HELEMENT(h,e1));
e = e1;
}
-
+
}
void heap_delmin(struct heap *h)
@@ -106,13 +107,15 @@ int heap_insert(struct heap *h, void *e)
{
h->max_size = h->max_size * HEAP_INCREASE_STEP;
h->data = realloc(h->data, (h->max_size + 1) * sizeof(heap_val_t));
+ if (!h->data) {
+ return 0;
+ }
}
h->num++;
*HELEMENT(h,h->num) = e;
_heap_bubble_up(h,h->num);
-
- return h->data ? 1 : 0;
+ return 1;
}
int heap_find(struct heap *h, void *elm) /* FIXME - very slow */
@@ -140,4 +143,3 @@ void heap_delete(struct heap *h, int e)
h->data = realloc(h->data, (h->max_size + 1) * sizeof(heap_val_t));
}
}
-