Skip to content

Commit 5ed7d72

Browse files
authored
Merge pull request #743 from M-Moawad/moawad-fix-wcast-align-memory-buffer-alloc
platform: fix -Wcast-align warnings in memory_buffer_alloc.c
2 parents 02bef92 + b16feb7 commit 5ed7d72

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

platform/memory_buffer_alloc.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ 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+
/* Double casting is required to prevent compilation warning on Clang-based
298+
* compilers when "-Wcast-align" is used. */
299+
new = (memory_header *) (void *) p;
298300

299301
new->size = cur->size - len - sizeof(memory_header);
300302
new->alloc = 0;
@@ -375,7 +377,9 @@ static void buffer_alloc_free(void *ptr)
375377
}
376378

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

380384
if (verify_header(hdr) != 0) {
381385
mbedtls_exit(1);
@@ -586,7 +590,9 @@ void mbedtls_memory_buffer_alloc_init(unsigned char *buf, size_t len)
586590
heap.buf = buf;
587591
heap.len = len;
588592

589-
heap.first = (memory_header *) buf;
593+
/* Double casting is required to prevent compilation warning on Clang-based
594+
* compilers when "-Wcast-align" is used. */
595+
heap.first = (memory_header *) (void *) buf;
590596
heap.first->size = len - sizeof(memory_header);
591597
heap.first->magic1 = MAGIC1;
592598
heap.first->magic2 = MAGIC2;

0 commit comments

Comments
 (0)