From f2bfb561625f0efcaef53cb57276967e01fa20bd Mon Sep 17 00:00:00 2001 From: arighi Date: Wed, 17 Mar 2010 11:53:12 +0000 Subject: [PATCH] heap: properly check the alignment in memory of a heap_buf_t pointer. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3225 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/struct/heap.c | 2 +- bertos/struct/heap.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/bertos/struct/heap.c b/bertos/struct/heap.c index 27f80325..33c6de2a 100644 --- a/bertos/struct/heap.c +++ b/bertos/struct/heap.c @@ -56,7 +56,7 @@ void heap_init(struct Heap* h, void* memory, size_t size) memset(memory, FREE_FILL_CODE, size); #endif - ASSERT2((((uintptr_t)memory % sizeof(heap_buf_t)) == 0), + ASSERT2(((size_t)memory % alignof(heap_buf_t)) == 0, "memory buffer is unaligned, please use the HEAP_DEFINE_BUF() macro to declare heap buffers!\n"); /* Initialize heap with a single big chunk */ diff --git a/bertos/struct/heap.h b/bertos/struct/heap.h index d76678b2..bcc54d52 100644 --- a/bertos/struct/heap.h +++ b/bertos/struct/heap.h @@ -71,8 +71,7 @@ typedef struct Heap * \param size Heap size in bytes. */ #define HEAP_DEFINE_BUF(name, size) \ - heap_buf_t name[((size) + sizeof(heap_buf_t) - 1) / sizeof(heap_buf_t)]; \ - STATIC_ASSERT(sizeof(name) % sizeof(heap_buf_t) == 0) + heap_buf_t name[((size) + sizeof(heap_buf_t) - 1) / sizeof(heap_buf_t)] /// Initialize \a heap within the buffer pointed by \a memory which is of \a size bytes void heap_init(struct Heap* heap, void* memory, size_t size); -- 2.25.1