From 82a5de7bf7f8f33bad24d017f30c52a4ff00d88e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Mon, 5 May 2014 14:05:24 +0200 Subject: [PATCH] Enforce alignment even if buffer is not aligned --- library/memory_buffer_alloc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/memory_buffer_alloc.c b/library/memory_buffer_alloc.c index caeaa46435..7dfeda9463 100644 --- a/library/memory_buffer_alloc.c +++ b/library/memory_buffer_alloc.c @@ -555,6 +555,13 @@ int memory_buffer_alloc_init( unsigned char *buf, size_t len ) platform_set_malloc_free( buffer_alloc_malloc, buffer_alloc_free ); #endif + if( (size_t) buf % POLARSSL_MEMORY_ALIGN_MULTIPLE ) + { + buf += POLARSSL_MEMORY_ALIGN_MULTIPLE + - (size_t) buf % POLARSSL_MEMORY_ALIGN_MULTIPLE; + len -= (size_t) buf % POLARSSL_MEMORY_ALIGN_MULTIPLE; + } + heap.buf = buf; heap.len = len;