summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-04-28 14:33:46 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:19:44 -0500
commit9263287a3604ab4f8c8cd2ed1dd3dc111dfd6039 (patch)
treee01593443a1e8e15bccd5b02b67bd536a851d78c
parent2724ce625c5b081e923f838755aa26ad1cd4c487 (diff)
downloadsamba-9263287a3604ab4f8c8cd2ed1dd3dc111dfd6039.tar.gz
samba-9263287a3604ab4f8c8cd2ed1dd3dc111dfd6039.tar.bz2
samba-9263287a3604ab4f8c8cd2ed1dd3dc111dfd6039.zip
r22555: Ensure our paranoid malloc functions return NULL on
size == 0 so we have a known behavior. Jeremy. (This used to be commit 27c0f2970842a6e07875c5591ded6352acf36a4e)
-rw-r--r--source3/lib/util.c12
1 files changed, 12 insertions, 0 deletions
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