diff options
author | Cy Schubert <cy@FreeBSD.org> | 2023-11-14 23:02:42 +0000 |
---|---|---|
committer | Cy Schubert <cy@FreeBSD.org> | 2023-11-14 23:02:42 +0000 |
commit | 5223d1d95fddcef6f9a36e264a5800bd907ade8b (patch) | |
tree | 818b1eba912c588e39058586485699385c3179fe /minheap-internal.h | |
parent | cbc620a473ce23d882ba3e9f91ec0c6c12dcd239 (diff) |
Diffstat (limited to 'minheap-internal.h')
-rw-r--r-- | minheap-internal.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/minheap-internal.h b/minheap-internal.h index b3b6f1fd497e..b3a0eb1fb589 100644 --- a/minheap-internal.h +++ b/minheap-internal.h @@ -70,7 +70,7 @@ struct event* min_heap_top_(min_heap_t* s) { return s->n ? *s->p : 0; } int min_heap_push_(min_heap_t* s, struct event* e) { - if (min_heap_reserve_(s, s->n + 1)) + if (s->n == UINT32_MAX || min_heap_reserve_(s, s->n + 1)) return -1; min_heap_shift_up_(s, s->n++, e); return 0; @@ -138,6 +138,10 @@ int min_heap_reserve_(min_heap_t* s, unsigned n) unsigned a = s->a ? s->a * 2 : 8; if (a < n) a = n; +#if (SIZE_MAX == UINT32_MAX) + if (a > SIZE_MAX / sizeof *p) + return -1; +#endif if (!(p = (struct event**)mm_realloc(s->p, a * sizeof *p))) return -1; s->p = p; |