avoid double evaluation in memset_check and memcpy_check
@@ -37,8 +37,24 @@ extern inline void* trace_memcpy_check(void *restrict to, const void *restrict f
/* Check memcpy and memset's arguments, if these are not right, log an error
*/
-#define memcpy_check( d, s, n ) do { if ( (n) ) { void *r = trace_memcpy_check( (d), (s) , (n), _S2N_DEBUG_LINE); if (r == NULL) { return -1; } } } while(0)
-#define memset_check( d, c, n ) do { if ( (n) ) { notnull_check( (d) ); memset( (d), (c), (n)); } } while(0)
+#define memcpy_check( d, s, n ) \
+ do { \
+ __typeof( n ) __tmp_n = ( n ); \
+ if ( __tmp_n ) { \
+ void *r = trace_memcpy_check( (d), (s) , (__tmp_n), _S2N_DEBUG_LINE); \
+ if (r == NULL) { return -1; } \
+ } \
+ } while(0)
+
+#define memset_check( d, c, n ) \
+ do { \
+ __typeof( n ) __tmp_n = ( n ); \
+ if ( __tmp_n ) { \
+ __typeof( d ) __tmp_d = ( d ); \
+ notnull_check( __tmp_d ); \
+ memset( __tmp_d, (c), __tmp_n); \
+ } \
+ } while(0)
/* Range check a number */
#define gte_check(n, min) do { if ( (n) < min ) { S2N_ERROR(S2N_ERR_SAFETY); } } while(0)
