diff options
author | Ondřej Surý <ondrej@sury.org> | 2013-06-28 12:59:40 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2013-06-28 12:59:40 +0200 |
commit | 124965832295a277b9ca6ae9fac4f45a74a36b2a (patch) | |
tree | f299e2335863f74e0be0707f84b85211baaf2d03 /src/common/heap.c | |
parent | 3d2d198c71a6b844b60fa9ef68801b66bba93361 (diff) | |
download | knot-upstream/1.3.0_rc3.tar.gz |
New upstream version 1.3.0~rc3upstream/1.3.0_rc3
Diffstat (limited to 'src/common/heap.c')
-rw-r--r-- | src/common/heap.c | 12 |
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)); } } - |