Problem:
If user option LWMEM_CFG_CLEAN_MEMORY is enabled (set to 1) there will be a memset-call inside prv_insert_free_block which will clean the free-ed blocks with zeros. Inside this memset-call is a macro, which either returns a block pointer or NULL, where the latter throws a compiler warning -Wnonull for the memset-call.
See the following code snippets of lwmem.c:
111: #define LWMEM_GET_PTR_FROM_BLOCK(block) (void *)((block) != NULL ? ((LWMEM_TO_BYTE_PTR(block)) + LWMEM_BLOCK_META_SIZE) : NULL)
219: /* Check valid inputs */
220: if (nb == NULL) {
221: return;
222: }
248: LWMEM_MEMSET(LWMEM_GET_PTR_FROM_BLOCK(nb), 0x00, nb->size - LWMEM_BLOCK_META_SIZE);
Compiler-warning:
null argument where non-null required (argument 1) [-Wnonnull]
Proposal for fix:
In this function nb is already checked for not beeing NULL, so the used macro itself does not need to do this again. As a fix for removing this warning I propose a second define, similar to LWMEM_GET_PTR_FROM_BLOCK, which does not check the input for beeing NULL but rather just returns the block. This macro should only be called, if nb is checked for beeing NULL earlier! My proposal code would look like this:
New macro definition:
/**
* \brief Get block handle from application pointer. Is not NULL-ptr safe! User must check for NULL pointers in advance to this call! Otherwise use @LWMEM_GET_PTR_FROM_BLOCK
* \param[in] block: Input pointer to get block from
*/
#define LWMEM_GET_PTR_FROM_BLOCK_UNSAFE(block) (void *)((LWMEM_TO_BYTE_PTR(block)) + LWMEM_BLOCK_META_SIZE)
Updated memset call:
248: LWMEM_MEMSET(LWMEM_GET_PTR_FROM_BLOCK_UNSAFE(nb), 0x00, nb->size - LWMEM_BLOCK_META_SIZE);