From 3327ffaa155b646d1ce04755388d1e0f8a522caa Mon Sep 17 00:00:00 2001 From: zhouji <956133287@qq.com> Date: Sun, 12 Dec 2021 11:16:26 +0800 Subject: [update] 使用memheap内存管理时,rt_malloc 0长度返回RT_NULL, 与slab与小内存管理等算法保持一致。 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/memheap.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/memheap.c b/src/memheap.c index 68a15d1a8e..9c3f570f29 100644 --- a/src/memheap.c +++ b/src/memheap.c @@ -850,6 +850,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 -- cgit v1.3.1