}
if (*pointer) {
- if (length_old) {
- if (length_new < length_old) {
+ #ifndef _f_memory_NO_zeroing_on_larger_
+ if (length_old) {
+ if (length_new < length_old) {
- // uint8_t * is of a data size size of 1, casting it to uint8_t should result in a single-length increment.
- // This is done to avoid problems with (void *) having arithmetic issues.
- memset((void *) (((uint8_t *) *pointer) + length_new), 0, type_size * (length_old - length_new));
+ // uint8_t * is of a data size size of 1, casting it to uint8_t should result in a single-length increment.
+ // This is done to avoid problems with (void *) having arithmetic issues.
+ memset((void *) (((uint8_t *) *pointer) + length_new), 0, type_size * (length_old - length_new));
+ }
}
- }
+ #endif // _f_memory_NO_zeroing_on_larger_
if (length_new) {
- void * const new_pointer = realloc(*pointer, type_size * length_new);
+ #ifdef _f_memory_USE_reallocarray_
+ void * const new_pointer = reallocarray(*pointer, length_new, type_size);
+ #else
+ void * const new_pointer = realloc(*pointer, type_size * length_new);
+ #endif // _f_memory_USE_reallocarray_
if (new_pointer) {
- if (length_new > length_old) {
+ #ifndef _f_memory_NO_zeroing_on_larger_
+ if (length_new > length_old) {
- // uint8_t * is of a data size size of 1, casting it to bool should result in a single-length increment.
- // This is done to avoid problems with (void *) having arithmetic issues.
- memset((void *) (((uint8_t *) new_pointer) + (type_size * length_old)), 0, type_size * (length_new - length_old));
- }
+ // uint8_t * is of a data size size of 1, casting it to bool should result in a single-length increment.
+ // This is done to avoid problems with (void *) having arithmetic issues.
+ memset((void *) (((uint8_t *) new_pointer) + (type_size * length_old)), 0, type_size * (length_new - length_old));
+ }
+ #endif // _f_memory_NO_zeroing_on_larger_
*pointer = new_pointer;
if (*pointer) {
if (length_new) {
- void * const new_pointer = realloc(*pointer, type_size * length_new);
+ #ifdef _f_memory_USE_reallocarray_
+ void * const new_pointer = reallocarray(*pointer, length_new, type_size);
+ #else
+ void * const new_pointer = realloc(*pointer, type_size * length_new);
+ #endif // _f_memory_USE_reallocarray_
if (new_pointer) {
- if (length_new > length_old) {
-
- // uint8_t * is of a data size size of 1, casting it to bool should result in a single-length increment.
- // This is done to avoid problems with (void *) having arithmetic issues.
- memset((void *) (((uint8_t *) new_pointer) + (type_size * length_old)), 0, type_size * (length_new - length_old));
- }
+ #ifndef _f_memory_NO_zeroing_on_larger_
+ if (length_new > length_old) {
+
+ // uint8_t * is of a data size size of 1, casting it to bool should result in a single-length increment.
+ // This is done to avoid problems with (void *) having arithmetic issues.
+ memset((void *) (((uint8_t *) new_pointer) + (type_size * length_old)), 0, type_size * (length_new - length_old));
+ }
+ #endif // _f_memory_NO_zeroing_on_larger_
*pointer = new_pointer;
# fss-0000
-_f_memory_FORCE_secure_memory_ all to-be removed address spaces are set to 0 before freeing or resizing.
-_f_memory_FORCE_fast_memory_ all to-be removed address spaces remain unchanged before freeing or resizing.
-_f_memory_USE_posix_memalign_ use POSIX memalign instead of aligned_alloc() (aligned_alloc() is in C as of C11 standard).
+_f_memory_FORCE_secure_memory_ All to-be removed address spaces are set to 0 before freeing or resizing.
+_f_memory_FORCE_fast_memory_ All to-be removed address spaces remain unchanged before freeing or resizing.
+_f_memory_USE_posix_memalign_ Use POSIX memalign instead of aligned_alloc() (aligned_alloc() is in C as of C11 standard).
+_f_memory_USE_reallocarray_ Use reallocarray() instead of realloc().
+_f_memory_NO_zeroing_on_larger_ Do not call memset() to zero out memory when the new size is larger for the newly added memory.