diff options
-rw-r--r-- | lib/alloc/arena_alloc.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/alloc/arena_alloc.c b/lib/alloc/arena_alloc.c index e5b99b7..eceb5b9 100644 --- a/lib/alloc/arena_alloc.c +++ b/lib/alloc/arena_alloc.c @@ -49,19 +49,18 @@ arena_alloc(arena *a, size_t sz, size_t n, size_t align) } for (struct _region *r = a->_head; r != nullptr; r = r->next) { - size_t off = pad(r->len, align); + size_t nlen, off = pad(r->len, align); /* Technically there are other ways to solve this… but at this point you might as well just fail */ - size_t padded_sz; - if (ckd_add(&padded_sz, off, sz)) { + if (ckd_add(&nlen, off, sz)) { errno = EOVERFLOW; return nullptr; } - if (padded_sz <= r->cap) { + if (nlen <= r->cap) { void *ret = (char *)r->data + off; - r->len = off + sz; + r->len = nlen; return ret; } } |