Skip to content

Commit 868fb8c

Browse files
committed
platform: fix -Wcast-align warnings in memory_buffer_alloc.c
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>
1 parent 1e3d9f1 commit 868fb8c

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

platform/memory_buffer_alloc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ static void *buffer_alloc_calloc(size_t n, size_t size)
294294
}
295295

296296
p = ((unsigned char *) cur) + sizeof(memory_header) + len;
297-
new = (memory_header *) p;
297+
new = (memory_header *) (void *) p;
298298

299299
new->size = cur->size - len - sizeof(memory_header);
300300
new->alloc = 0;
@@ -375,7 +375,7 @@ static void buffer_alloc_free(void *ptr)
375375
}
376376

377377
p -= sizeof(memory_header);
378-
hdr = (memory_header *) p;
378+
hdr = (memory_header *) (void *) p;
379379

380380
if (verify_header(hdr) != 0) {
381381
mbedtls_exit(1);
@@ -586,7 +586,7 @@ void mbedtls_memory_buffer_alloc_init(unsigned char *buf, size_t len)
586586
heap.buf = buf;
587587
heap.len = len;
588588

589-
heap.first = (memory_header *) buf;
589+
heap.first = (memory_header *) (void *) buf;
590590
heap.first->size = len - sizeof(memory_header);
591591
heap.first->magic1 = MAGIC1;
592592
heap.first->magic2 = MAGIC2;

0 commit comments

Comments
 (0)