From b65b4b6c1f3cb29e30a4d7e276be36624d5f1bd8 Mon Sep 17 00:00:00 2001 From: scottmk Date: Wed, 7 Jan 2009 18:28:53 +0000 Subject: [PATCH] Rewrote the OSRF_MALLOC macro so that it evaluates each of its arguments only once. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1578 9efc2488-bf62-4759-914b-345cdb29e865 --- include/opensrf/utils.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/include/opensrf/utils.h b/include/opensrf/utils.h index ab24e8f..ae2a7ee 100644 --- a/include/opensrf/utils.h +++ b/include/opensrf/utils.h @@ -33,13 +33,15 @@ GNU General Public License for more details. #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 -- 2.43.2