From cf34afd2cc64ce9f0e5b5c577284bd087bb94357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Mon, 16 Jan 2023 14:35:35 +0100 Subject: [PATCH] testsuite: coverage: fix -Wcast-align warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While porting the coverage.c file from RIOT to Zephyr, which employs different compiler flags, I noticed several -Wcast-align GCC warnings on arm. I think, as is, the current implementation may perform unaligned memory accesses which may not be supported on certain platforms. To workaround that, I have rewritten the code for RIOT using bytewise-writes with `memcpy`. Signed-off-by: Sören Tempel --- subsys/testsuite/coverage/coverage.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/subsys/testsuite/coverage/coverage.c b/subsys/testsuite/coverage/coverage.c index 75d3b090178..e787135ffdc 100644 --- a/subsys/testsuite/coverage/coverage.c +++ b/subsys/testsuite/coverage/coverage.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "coverage.h" K_HEAP_DEFINE(gcov_heap, CONFIG_COVERAGE_GCOV_HEAP_SIZE); @@ -38,12 +39,9 @@ void __gcov_exit(void) * buff_write_u64 - Store 64 bit data on a buffer and return the size */ -#define MASK_32BIT (0xffffffffUL) static inline void buff_write_u64(void *buffer, size_t *off, uint64_t v) { - *((uint32_t *)((uint8_t *)buffer + *off) + 0) = (uint32_t)(v & MASK_32BIT); - *((uint32_t *)((uint8_t *)buffer + *off) + 1) = (uint32_t)((v >> 32) & - MASK_32BIT); + memcpy((uint8_t *)buffer + *off, (uint8_t *)&v, sizeof(v)); *off = *off + sizeof(uint64_t); } @@ -52,7 +50,7 @@ static inline void buff_write_u64(void *buffer, size_t *off, uint64_t v) */ static inline void buff_write_u32(void *buffer, size_t *off, uint32_t v) { - *((uint32_t *)((uint8_t *)buffer + *off)) = v; + memcpy((uint8_t *)buffer + *off, (uint8_t *)&v, sizeof(v)); *off = *off + sizeof(uint32_t); }