From f3a551526d8419e0660ab2a451f0706749fd75a3 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 7 Aug 2023 20:21:26 -0500 Subject: [PATCH] Cleanup: Add explicit casts in the f_memory memset() calls. The pointer is cast to uint8_t to perform the arithmetic. The pointer is not cast back but the cast happens in the function call. Be explicit and designate that the cast back to a void pointer is intentional. --- level_0/f_memory/c/memory.c | 4 +--- level_0/f_memory/c/private-memory.c | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/level_0/f_memory/c/memory.c b/level_0/f_memory/c/memory.c index 1f6c929..945c62d 100644 --- a/level_0/f_memory/c/memory.c +++ b/level_0/f_memory/c/memory.c @@ -122,9 +122,7 @@ extern "C" { } #endif // _f_memory_USE_posix_memalign_ - // uint8_t * is of a data 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(((uint8_t *) *pointer), 0, length); + memset(*pointer, 0, length); return F_none; } diff --git a/level_0/f_memory/c/private-memory.c b/level_0/f_memory/c/private-memory.c index f48de2e..6115009 100644 --- a/level_0/f_memory/c/private-memory.c +++ b/level_0/f_memory/c/private-memory.c @@ -19,7 +19,7 @@ extern "C" { // 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(((uint8_t *) *pointer) + length_new, 0, type_size * (length_old - length_new)); + memset((void *) (((uint8_t *) *pointer) + length_new), 0, type_size * (length_old - length_new)); } } @@ -31,7 +31,7 @@ extern "C" { // 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(((uint8_t *) new_pointer) + (type_size * length_old), 0, type_size * (length_new - length_old)); + memset((void *) (((uint8_t *) new_pointer) + (type_size * length_old)), 0, type_size * (length_new - length_old)); } *pointer = new_pointer; @@ -77,7 +77,7 @@ extern "C" { // 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(((uint8_t *) new_pointer) + (type_size * length_old), 0, type_size * (length_new - length_old)); + memset((void *) (((uint8_t *) new_pointer) + (type_size * length_old)), 0, type_size * (length_new - length_old)); } *pointer = new_pointer; -- 1.8.3.1