Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions platform/memory_buffer_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ static void *buffer_alloc_calloc(size_t n, size_t size)
}

p = ((unsigned char *) cur) + sizeof(memory_header) + len;
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.


new->size = cur->size - len - sizeof(memory_header);
new->alloc = 0;
Expand Down Expand Up @@ -375,7 +377,9 @@ static void buffer_alloc_free(void *ptr)
}

p -= sizeof(memory_header);
hdr = (memory_header *) p;
/* Double casting is required to prevent compilation warning on Clang-based
* compilers when "-Wcast-align" is used. */
hdr = (memory_header *) (void *) p;

if (verify_header(hdr) != 0) {
mbedtls_exit(1);
Expand Down Expand Up @@ -586,7 +590,9 @@ void mbedtls_memory_buffer_alloc_init(unsigned char *buf, size_t len)
heap.buf = buf;
heap.len = len;

heap.first = (memory_header *) buf;
/* Double casting is required to prevent compilation warning on Clang-based
* compilers when "-Wcast-align" is used. */
heap.first = (memory_header *) (void *) buf;
heap.first->size = len - sizeof(memory_header);
heap.first->magic1 = MAGIC1;
heap.first->magic2 = MAGIC2;
Expand Down