[Opensrf-commits] r1578 - trunk/include/opensrf

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Jan 7 13:28:56 EST 2009


Author: scottmk
Date: 2009-01-07 13:28:53 -0500 (Wed, 07 Jan 2009)
New Revision: 1578

Modified:
   trunk/include/opensrf/utils.h
Log:
Rewrote the OSRF_MALLOC macro so that it evaluates each
of its arguments only once.


Modified: trunk/include/opensrf/utils.h
===================================================================
--- trunk/include/opensrf/utils.h	2009-01-07 17:40:26 UTC (rev 1577)
+++ trunk/include/opensrf/utils.h	2009-01-07 18:28:53 UTC (rev 1578)
@@ -33,13 +33,15 @@
 
 #define OSRF_MALLOC(ptr, size) \
 	do {\
-		ptr = (void*) malloc( size ); \
-		if( ptr == NULL ) { \
-			perror("OSRF_MALLOC(): Out of Memory" );\
-			exit(99); \
-		} \
-		memset( ptr, 0, size );\
-	} while(0)
+			size_t _size = size; \
+			void* p = malloc( _size ); \
+			if( p == NULL ) { \
+				perror("OSRF_MALLOC(): Out of Memory" ); \
+				exit(99); \
+			} \
+			memset( p, 0, _size ); \
+			(ptr) = p; \
+		} while(0)
 
 #ifdef NDEBUG
 // The original ... replace with noop once no more errors occur in NDEBUG mode



More information about the opensrf-commits mailing list