Skip to content

[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
valeriosetti:backport-pr743
Apr 22, 2026
Merged

[backport 1.1] platform: fix -Wcast-align warnings in memory_buffer_alloc.c#757
valeriosetti merged 1 commit intoMbed-TLS:tf-psa-crypto-1.1from
valeriosetti:backport-pr743

Conversation

@valeriosetti
Copy link
Copy Markdown
Contributor

Description

Backport of #743

PR checklist

  • changelog not required because: minor fix
  • framework PR not required
  • mbedtls development PR not required because: no change there
  • mbedtls 3.6 PR provided Mbed-TLS/mbedtls# | not required because:
  • tests provided | not required because:

@valeriosetti valeriosetti added needs-review Every commit must be reviewed by at least two team members needs-reviewer This PR needs someone to pick it up for review priority-high High priority - will be reviewed soon size-xs Estimated task size: extra small (a few hours at most) labels Apr 14, 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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, meant to add this as a comment. So I've re-requested the review.

@bjwtaylor bjwtaylor self-requested a review April 15, 2026 08:13
Copy link
Copy Markdown
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-project-automation github-project-automation Bot moved this from In Development to Has Approval in Roadmap pull requests (new board) Apr 15, 2026
@gilles-peskine-arm
Copy link
Copy Markdown
Contributor

The CI is failing due to an outdated framework submodule. Please rebase on top of the latest tf-psa-crypto-1.1 to fix it.

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>
@valeriosetti valeriosetti removed the needs-reviewer This PR needs someone to pick it up for review label Apr 15, 2026
@valeriosetti
Copy link
Copy Markdown
Contributor Author

The CI is failing due to an outdated framework submodule. Please rebase on top of the latest tf-psa-crypto-1.1 to fix it.

Done ;)

Copy link
Copy Markdown
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@valeriosetti valeriosetti added this pull request to the merge queue Apr 22, 2026
Merged via the queue into Mbed-TLS:tf-psa-crypto-1.1 with commit a089af1 Apr 22, 2026
3 checks passed
@github-project-automation github-project-automation Bot moved this from Has Approval to Done in Roadmap pull requests (new board) Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review Every commit must be reviewed by at least two team members priority-high High priority - will be reviewed soon size-xs Estimated task size: extra small (a few hours at most)

Development

Successfully merging this pull request may close these issues.

4 participants