From a4ba059034124cbdc0232b805a7fdf07994c8618 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Fri, 8 Aug 2003 10:30:12 +0000 Subject: Add in a MALLOC_GLIBC_COMPAT option to let people decide if they want glibc style malloc(0) behavior --- libc/stdlib/malloc-930716/malloc.c | 5 +++++ libc/stdlib/malloc/malloc.c | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'libc') diff --git a/libc/stdlib/malloc-930716/malloc.c b/libc/stdlib/malloc-930716/malloc.c index 2467da41c..dce32b90b 100644 --- a/libc/stdlib/malloc-930716/malloc.c +++ b/libc/stdlib/malloc-930716/malloc.c @@ -160,9 +160,14 @@ void * __malloc_unlocked (size_t size) size_t log, block, blocks, i, lastblocks, start; struct list *next; +#if defined(__MALLOC_GLIBC_COMPAT__) + if (size == 0) + size++; +#else /* Some programs will call malloc (0). Lets be strict and return NULL */ if (size == 0) return NULL; +#endif if (size < sizeof (struct list)) size = sizeof (struct list); diff --git a/libc/stdlib/malloc/malloc.c b/libc/stdlib/malloc/malloc.c index 7bbd2726b..5f88cf48e 100644 --- a/libc/stdlib/malloc/malloc.c +++ b/libc/stdlib/malloc/malloc.c @@ -184,8 +184,13 @@ malloc (size_t size) __heap_check (&__malloc_heap, "malloc"); #endif +#if defined(__MALLOC_GLIBC_COMPAT__) if (size == 0) return 0; +#else + if (size == 0) + size++; +#endif return malloc_from_heap (size, &__malloc_heap); } -- cgit v1.2.3