From 9263287a3604ab4f8c8cd2ed1dd3dc111dfd6039 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 28 Apr 2007 14:33:46 +0000 Subject: r22555: Ensure our paranoid malloc functions return NULL on size == 0 so we have a known behavior. Jeremy. (This used to be commit 27c0f2970842a6e07875c5591ded6352acf36a4e) --- source3/lib/util.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/util.c b/source3/lib/util.c index a9065816cf..1e64db38fc 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -942,6 +942,9 @@ BOOL yesno(char *p) void *malloc_(size_t size) { + if (size == 0) { + return NULL; + } #undef malloc return malloc(size); #define malloc(s) __ERROR_DONT_USE_MALLOC_DIRECTLY @@ -953,6 +956,9 @@ void *malloc_(size_t size) static void *calloc_(size_t count, size_t size) { + if (size == 0 || count == 0) { + return NULL; + } #undef calloc return calloc(count, size); #define calloc(n,s) __ERROR_DONT_USE_CALLOC_DIRECTLY @@ -981,6 +987,9 @@ void *malloc_array(size_t el_size, unsigned int count) return NULL; } + if (el_size == 0 || count == 0) { + return NULL; + } #if defined(PARANOID_MALLOC_CHECKER) return malloc_(el_size*count); #else @@ -1010,6 +1019,9 @@ void *calloc_array(size_t size, size_t nmemb) if (nmemb >= MAX_ALLOC_SIZE/size) { return NULL; } + if (size == 0 || nmemb == 0) { + return NULL; + } #if defined(PARANOID_MALLOC_CHECKER) return calloc_(nmemb, size); #else -- cgit