diff options
author | Jeremy Allison <jra@samba.org> | 2007-04-28 14:33:46 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2007-04-28 14:33:46 +0000 |
commit | aab41f2bb4b1cdb17578249a49580c634f547be0 (patch) | |
tree | 53a6dec81cdc1475578eb5bd7085a40dcc02407d | |
parent | 3b746f46dc14668d1d95b2d4f8253a3dcbe8842a (diff) | |
download | samba-aab41f2bb4b1cdb17578249a49580c634f547be0.tar.gz samba-aab41f2bb4b1cdb17578249a49580c634f547be0.tar.xz samba-aab41f2bb4b1cdb17578249a49580c634f547be0.zip |
r22555: Ensure our paranoid malloc functions return NULL on
size == 0 so we have a known behavior.
Jeremy.
-rw-r--r-- | source/lib/util.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/source/lib/util.c b/source/lib/util.c index f49af133adb..07d99b8769c 100644 --- a/source/lib/util.c +++ b/source/lib/util.c @@ -921,6 +921,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 @@ -932,6 +935,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 @@ -960,6 +966,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 @@ -989,6 +998,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 |