r22555: Ensure our paranoid malloc functions return NULL on
authorJeremy Allison <jra@samba.org>
Sat, 28 Apr 2007 14:33:46 +0000 (14:33 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:19:44 +0000 (12:19 -0500)
size == 0 so we have a known behavior.
Jeremy.
(This used to be commit 27c0f2970842a6e07875c5591ded6352acf36a4e)

source3/lib/util.c

index a9065816cffbd6ed1345400faadcc6e011a7f1c1..1e64db38fc3d6138f1a46ef23c32ff80673984e7 100644 (file)
@@ -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