platform: fix -Wcast-align warnings in memory_buffer_alloc.c#743
Conversation
|
@M-Moawad I suspect that using "Fixes" in the description of this PR will close the pointed issue once this PR is merged which is not correct. That issue will only be closed when this PR is cherry-picked to Zephyr fork of this repo |
|
Modified |
Cast from 'unsigned char *' to 'memory_header *' through an intermediate 'void *' to suppress -Wcast-align warnings. Some Clang-based toolchains (e.g. MetaWare/ARC) enable -Wcast-align as part of -Wall, unlike standard Clang on x86/ARM. Combined with -Werror this turns the casts into fatal build errors. The casts are already alignment-safe at runtime: - In mbedtls_memory_buffer_alloc_init(), buf is explicitly aligned to MBEDTLS_MEMORY_ALIGN_MULTIPLE before the cast. - In buffer_alloc_calloc(), p is computed from an aligned base plus aligned offsets (sizeof(memory_header) and len are both multiples of MBEDTLS_MEMORY_ALIGN_MULTIPLE). - In buffer_alloc_free(), p is derived from a previously aligned allocation pointer minus the aligned header size. Signed-off-by: Mohamed Moawad <moawad@synopsys.com>
868fb8c to
b16feb7
Compare
There was a problem hiding this comment.
LGTM
At runtime, we know that the start of the heap is aligned to MBEDTLS_MEMORY_ALIGN_MULTIPLE, which is supposed to be good enough for the platform's alignment requirements. So the warning is spurious, but the compiler can't know. This patch silences the warning in a sensible way.
OK to not have a changelog entry since silencing compiler warnings is on a best effort basis and this one doesn't have an issue on our bug tracker.
|
Thanks for the patch! Can you please backport it to the |
I did those: |
Cast from 'unsigned char *' to 'memory_header *' through an intermediate 'void *' to suppress -Wcast-align warnings.
Some Clang-based toolchains (e.g. MetaWare/ARC) enable -Wcast-align as part of -Wall, unlike standard Clang on x86/ARM. Combined with -Werror this turns the casts into fatal build errors.
The casts are already alignment-safe at runtime:
Original issue reported on zephyr: zephyrproject-rtos/zephyr#106712
PR checklist