Use inline fuction to check if either to or from pointers are null
/* NULL check a pointer */
#define notnull_check( ptr ) do { if ( (ptr) == NULL ) { S2N_ERROR(S2N_ERR_NULL); } } while(0)
+extern inline void* trace_memcpy_check(void *restrict to, const void *restrict from, size_t size, const char *debug_str)
+{
+ if(to == NULL || from == NULL) {
+ s2n_errno = S2N_ERR_NULL;
+ s2n_debug_str = debug_str;
+ return NULL;
+ }
+
+ return memcpy(to, from, size);
+}
+
/* Check memcpy and memset's arguments, if these are not right, log an error
*/
-#define memcpy_check( d, s, n ) do { if ( (n) ) { notnull_check( (s) ); notnull_check( (d) ); memcpy( (d), (s), (n)); } } while(0)
+#define memcpy_check( d, s, n ) do { if ( (n) ) { void *r = trace_memcpy_check( (d), (s) , (n), "Error encountered in " __FILE__ " line " STRING__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)
/* Range check a number */
