Add `-Wconversion` in CMakeLists.txt (#712)
Also fix warnings generated by this flag.
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6faa931..678b6a6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -260,6 +260,7 @@
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wextra>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wpedantic>
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Werror>
+ $<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wconversion>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Weverything>
# Suppressions required to build clean with clang.
diff --git a/portable/MemMang/heap_4.c b/portable/MemMang/heap_4.c
index c7a8209..c82933e 100644
--- a/portable/MemMang/heap_4.c
+++ b/portable/MemMang/heap_4.c
@@ -421,7 +421,7 @@
/* pxEnd is used to mark the end of the list of free blocks and is inserted
* at the end of the heap space. */
uxAddress = ( portPOINTER_SIZE_TYPE ) ( pucAlignedHeap + xTotalHeapSize );
- uxAddress -= xHeapStructSize;
+ uxAddress -= ( portPOINTER_SIZE_TYPE ) xHeapStructSize;
uxAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK );
pxEnd = ( BlockLink_t * ) uxAddress;
pxEnd->xBlockSize = 0;
diff --git a/portable/MemMang/heap_5.c b/portable/MemMang/heap_5.c
index db9e1eb..bd641dc 100644
--- a/portable/MemMang/heap_5.c
+++ b/portable/MemMang/heap_5.c
@@ -508,7 +508,7 @@
configASSERT( pxEnd != NULL );
/* Check blocks are passed in with increasing start addresses. */
- configASSERT( xAddress > ( size_t ) pxEnd );
+ configASSERT( ( size_t ) xAddress > ( size_t ) pxEnd );
}
/* Remember the location of the end marker in the previous region, if
@@ -517,9 +517,9 @@
/* pxEnd is used to mark the end of the list of free blocks and is
* inserted at the end of the region space. */
- xAddress = xAlignedHeap + xTotalRegionSize;
- xAddress -= xHeapStructSize;
- xAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK );
+ xAddress = xAlignedHeap + ( portPOINTER_SIZE_TYPE ) xTotalRegionSize;
+ xAddress -= ( portPOINTER_SIZE_TYPE ) xHeapStructSize;
+ xAddress &= ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK );
pxEnd = ( BlockLink_t * ) xAddress;
pxEnd->xBlockSize = 0;
pxEnd->pxNextFreeBlock = NULL;