diff options
| author | ousugo <[email protected]> | 2021-12-14 10:42:18 +0800 |
|---|---|---|
| committer | ousugo <[email protected]> | 2021-12-14 10:42:18 +0800 |
| commit | 4820dbb0b3a15a62f4cd5f3e20fb4e02e4bfbb20 (patch) | |
| tree | 27698aa9180b0c25dd9c4d9ced3320da10360b1d /src/memheap.c | |
| parent | a237f805b940db16ef0d0009e56eb183f5713c07 (diff) | |
| parent | c5208a7d19871573dcb719358d34d3effa0682e9 (diff) | |
Merge branch 'master' into addAnnotation
Diffstat (limited to 'src/memheap.c')
| -rw-r--r-- | src/memheap.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/memheap.c b/src/memheap.c index 68a15d1a8e..e96b402bcf 100644 --- a/src/memheap.c +++ b/src/memheap.c @@ -832,13 +832,16 @@ static struct rt_memheap _heap; */ void rt_system_heap_init(void *begin_addr, void *end_addr) { - RT_ASSERT((rt_uint32_t)end_addr > (rt_uint32_t)begin_addr); + RT_ASSERT((rt_size_t)end_addr > (rt_size_t)begin_addr); + + rt_size_t begin_align = RT_ALIGN((rt_size_t)begin_addr, RT_ALIGN_SIZE); + rt_size_t end_align = RT_ALIGN_DOWN((rt_size_t)end_addr, RT_ALIGN_SIZE); /* initialize a default heap in the system */ rt_memheap_init(&_heap, "heap", - begin_addr, - (rt_uint32_t)end_addr - (rt_uint32_t)begin_addr); + (void *)begin_align, + end_align - begin_align); } /** @@ -850,6 +853,10 @@ void *rt_malloc(rt_size_t size) { void *ptr; + /* zero size, return RT_NULL */ + if (size == 0) + return RT_NULL; + /* try to allocate in system heap */ ptr = rt_memheap_alloc(&_heap, size); #ifdef RT_USING_MEMHEAP_AUTO_BINDING |
