[backport 1.1] platform: fix -Wcast-align warnings in memory_buffer_alloc.c#757
Merged
valeriosetti merged 1 commit intoMbed-TLS:tf-psa-crypto-1.1from Apr 22, 2026
Merged
Conversation
This was referenced Apr 14, 2026
bjwtaylor
approved these changes
Apr 15, 2026
| new = (memory_header *) p; | ||
| /* Double casting is required to prevent compilation warning on Clang-based | ||
| * compilers when "-Wcast-align" is used. */ | ||
| new = (memory_header *) (void *) p; |
Contributor
There was a problem hiding this comment.
Will this suppress valid warnings, such as when MBEDTLS_MEMORY_ALIGN_MULTIPLE is kept at 4 however the memory is 8 bit aligned and do we need a more robust solution? Or is it sufficient to just suppress the warning?
Contributor
There was a problem hiding this comment.
Apologies, meant to add this as a comment. So I've re-requested the review.
Contributor
|
The CI is failing due to an outdated |
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>
16e0258 to
af8124b
Compare
Contributor
Author
Done ;) |
bjwtaylor
approved these changes
Apr 22, 2026
Merged
via the queue into
Mbed-TLS:tf-psa-crypto-1.1
with commit Apr 22, 2026
a089af1
3 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Backport of #743
PR checklist