kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit e47806c66908630bf4a917bb9465ecc71fe8a472
parent 620cc231dcdd4534f59bda7d27a50e3a7f3b9311
Author: Joris Vink <joris@coders.se>
Date:   Wed, 25 Jan 2017 22:07:08 +0100

allow memory allocators to deal with 0 bytes.

we just increase the lenght requested to 8 bytes if we get a 0 byte request.

additionally when kore_realloc() is called check if we actually have
to do the work, if not just return the original pointer.

Diffstat:
src/mem.c | 9+++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/src/mem.c b/src/mem.c @@ -78,7 +78,7 @@ kore_malloc(size_t len) size_t mlen, idx, *plen; if (len == 0) - fatal("kore_malloc(): zero size"); + len = 8; if (len <= KORE_MEM_BLOCK_SIZE_MAX) { idx = memblock_index(len); @@ -105,12 +105,11 @@ kore_realloc(void *ptr, size_t len) struct meminfo *mem; void *nptr; - if (len == 0) - fatal("kore_realloc(): zero size"); - if (ptr == NULL) { nptr = kore_malloc(len); } else { + if (len == KORE_MEMSIZE(ptr)) + return (ptr); mem = KORE_MEMINFO(ptr); if (mem->magic != KORE_MEM_MAGIC) fatal("kore_realloc(): magic boundary not found"); @@ -126,8 +125,6 @@ kore_realloc(void *ptr, size_t len) void * kore_calloc(size_t memb, size_t len) { - if (memb == 0 || len == 0) - fatal("kore_calloc(): zero size"); if (SIZE_MAX / memb < len) fatal("kore_calloc(): memb * len > SIZE_MAX");