svn commit: samba r22555 - in branches: SAMBA_3_0/source/lib SAMBA_3_0_25/source/lib

jra at samba.org jra at samba.org
Sat Apr 28 14:33:47 GMT 2007


Author: jra
Date: 2007-04-28 14:33:46 +0000 (Sat, 28 Apr 2007)
New Revision: 22555

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=22555

Log:
Ensure our paranoid malloc functions return NULL on
size == 0 so we have a known behavior.
Jeremy.

Modified:
   branches/SAMBA_3_0/source/lib/util.c
   branches/SAMBA_3_0_25/source/lib/util.c


Changeset:
Modified: branches/SAMBA_3_0/source/lib/util.c
===================================================================
--- branches/SAMBA_3_0/source/lib/util.c	2007-04-28 13:52:49 UTC (rev 22554)
+++ branches/SAMBA_3_0/source/lib/util.c	2007-04-28 14:33:46 UTC (rev 22555)
@@ -942,6 +942,9 @@
 
 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 @@
 
 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 @@
 		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 @@
 	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

Modified: branches/SAMBA_3_0_25/source/lib/util.c
===================================================================
--- branches/SAMBA_3_0_25/source/lib/util.c	2007-04-28 13:52:49 UTC (rev 22554)
+++ branches/SAMBA_3_0_25/source/lib/util.c	2007-04-28 14:33:46 UTC (rev 22555)
@@ -921,6 +921,9 @@
 
 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 @@
 
 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 @@
 		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 @@
 	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



More information about the samba-cvs mailing list