From 0124617e7eb36a2f23f2c3e3d5677e585ec4d3ee Mon Sep 17 00:00:00 2001 From: seagate Date: Thu, 23 Apr 2026 12:06:58 +0530 Subject: [PATCH 1/2] Commented the dead code for bit_manip.c --- src/bit_manip.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/bit_manip.c b/src/bit_manip.c index 73bb9394..5773898f 100644 --- a/src/bit_manip.c +++ b/src/bit_manip.c @@ -152,6 +152,7 @@ static M_INLINE size_t gen_bit_width(uint8_t msb, uint8_t lsb) static M_INLINE uint64_t gen_safe_mask_u64(size_t width) { + /* Check not needed here as this function is only called after validating width against GENERIC_WIDTH_64 by the functions which call it. if (width >= GENERIC_WIDTH_64) { return UINT64_MAX; @@ -161,12 +162,14 @@ static M_INLINE uint64_t gen_safe_mask_u64(size_t width) { return UINT64_C(0); } + */ return (UINT64_C(1) << width) - UINT64_C(1); } static M_INLINE uint32_t gen_safe_mask_u32(size_t width) { + /* Check not needed here as this function is only called after validating width against GENERIC_WIDTH_32 by the functions which call it. if (width >= GENERIC_WIDTH_32) { return UINT32_MAX; @@ -176,12 +179,14 @@ static M_INLINE uint32_t gen_safe_mask_u32(size_t width) { return UINT32_C(0); } + */ return (UINT32_C(1) << width) - UINT32_C(1); } static M_INLINE uint16_t gen_safe_mask_u16(size_t width) { + /* Check not needed here as this function is only called after validating width against GENERIC_WIDTH_16 by the functions which call it. if (width >= GENERIC_WIDTH_16) { return UINT16_MAX; @@ -191,12 +196,14 @@ static M_INLINE uint16_t gen_safe_mask_u16(size_t width) { return UINT16_C(0); } + */ return M_STATIC_CAST(uint16_t, (UINT32_C(1) << width) - UINT32_C(1)); } static M_INLINE uint8_t gen_safe_mask_u8(size_t width) { + /* Check not needed here as this function is only called after validating width against GENERIC_WIDTH_8 by the functions which call it. if (width >= GENERIC_WIDTH_8) { return UINT8_MAX; @@ -206,6 +213,7 @@ static M_INLINE uint8_t gen_safe_mask_u8(size_t width) { return UINT8_C(0); } + */ return M_STATIC_CAST(uint8_t, (UINT32_C(1) << width) - UINT32_C(1)); } @@ -214,20 +222,24 @@ static M_INLINE uint64_t gen_extract_u64(uint64_t val, uint8_t msb, uint8_t lsb) { size_t width = gen_bit_width(msb, lsb); + /* Check not needed here as this function is only called after validating the condition by the functions which call it. if (width == GENERIC_WIDTH_0) { return UINT64_C(0); } + */ if (width >= GENERIC_WIDTH_64 && lsb == 0) { return val; } + /* Check not needed here as this function is only called after validating the condition by the functions which call it. if (lsb >= GENERIC_WIDTH_64) { return UINT64_C(0); } + */ return M_STATIC_CAST(uint64_t, (val >> lsb) & gen_safe_mask_u64(width)); } @@ -236,20 +248,24 @@ static M_INLINE uint32_t gen_extract_u32(uint32_t val, uint8_t msb, uint8_t lsb) { size_t width = gen_bit_width(msb, lsb); + /* Check not needed here as this function is only called after validating the condition by the functions which call it. if (width == GENERIC_WIDTH_0) { return UINT32_C(0); } + */ if (width >= GENERIC_WIDTH_32 && lsb == 0) { return val; } + /* Check not needed here as this function is only called after validating the condition by the functions which call it. if (lsb >= GENERIC_WIDTH_32) { return UINT32_C(0); } + */ return M_STATIC_CAST(uint32_t, (val >> lsb) & gen_safe_mask_u32(width)); } @@ -258,20 +274,24 @@ static M_INLINE uint16_t gen_extract_u16(uint16_t val, uint8_t msb, uint8_t lsb) { size_t width = gen_bit_width(msb, lsb); + /* Check not needed here as this function is only called after validating the condition by the functions which call it. if (width == GENERIC_WIDTH_0) { return M_STATIC_CAST(uint16_t, UINT32_C(0)); } + */ if (width >= GENERIC_WIDTH_16 && lsb == 0) { return val; } + /* Check not needed here as this function is only called after validating the condition by the functions which call it. if (lsb >= GENERIC_WIDTH_16) { return M_STATIC_CAST(uint16_t, UINT32_C(0)); } + */ return M_STATIC_CAST(uint16_t, (val >> lsb) & gen_safe_mask_u16(width)); } @@ -280,20 +300,24 @@ static M_INLINE uint8_t gen_extract_u8(uint8_t val, uint8_t msb, uint8_t lsb) { size_t width = gen_bit_width(msb, lsb); + /* Check not needed here as this function is only called after validating the condition by the functions which call it. if (width == GENERIC_WIDTH_0) { return M_STATIC_CAST(uint8_t, UINT32_C(0)); } + */ if (width >= GENERIC_WIDTH_8 && lsb == 0) { return val; } + /* Check not needed here as this function is only called after validating the condition by the functions which call it. if (lsb >= GENERIC_WIDTH_8) { return M_STATIC_CAST(uint8_t, UINT32_C(0)); } + */ return M_STATIC_CAST(uint8_t, (val >> lsb) & gen_safe_mask_u8(width)); } From deee1017b950691dc12d73ada168f90ab83d3d37 Mon Sep 17 00:00:00 2001 From: seagate Date: Thu, 23 Apr 2026 12:23:45 +0530 Subject: [PATCH 2/2] Removed dead code from memory_safety.c --- src/memory_safety.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/memory_safety.c b/src/memory_safety.c index 82833479..784bd4dc 100644 --- a/src/memory_safety.c +++ b/src/memory_safety.c @@ -584,7 +584,7 @@ M_NODISCARD M_PARAM_RW(1) M_MALLOC_SIZE(2) void* safe_reallocf(void** block, siz else { void* newblock = realloc(*block, size); - if (newblock == M_NULLPTR && size != SIZE_T_C(0)) + if (newblock == M_NULLPTR) { free(*block); *block = M_NULLPTR; @@ -729,14 +729,7 @@ void* safe_realloc_aligned(void* block, size_t originalSize, size_t size, size_t // than a simple return realloc, the purpose of this is to help reduce // false positives with SAST tools. void* newblock = realloc_aligned(block, originalSize, size, alignment); - if (newblock == M_NULLPTR) - { - return M_NULLPTR; - } - else - { - return newblock; - } + return newblock; } } @@ -770,7 +763,7 @@ void* safe_reallocf_aligned(void** block, size_t originalSize, size_t size, size alignment = alignment_Round_Up(alignment); size = aligned_Size_Round_Up(size, alignment); void* newblock = realloc_aligned(*block, originalSize, size, alignment); - if (newblock == M_NULLPTR && *block && size != SIZE_T_C(0)) + if (newblock == M_NULLPTR && *block) { free_aligned(*block); *block = M_NULLPTR;