This is an automated email from the ASF dual-hosted git repository. ligd pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push: new d01bbaecc1 sim/heap: malloc returns a valid pointer when allocating 0 bytes. d01bbaecc1 is described below commit d01bbaecc1063fa98af5737cb4aeba5b20f2d454 Author: yinshengkai <yinsheng...@xiaomi.com> AuthorDate: Mon Nov 13 15:35:47 2023 +0800 sim/heap: malloc returns a valid pointer when allocating 0 bytes. The default heap management in nuttx returns a valid memory address when malloc(0). In sim_heap, malloc(0) returns NULL, aligning the behavior of sim_heap with mm_heap The man manual describes malloc as follows: https://man7.org/linux/man-pages/man3/malloc.3.html The malloc() function allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized. If size is 0, then malloc() returns a unique pointer value that can later be successfully passed to free(). (See "Nonportable behavior" for portability issues.) Signed-off-by: yinshengkai <yinsheng...@xiaomi.com> --- arch/sim/src/sim/sim_heap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/sim/src/sim/sim_heap.c b/arch/sim/src/sim/sim_heap.c index e95b559ff1..7b95441f7a 100644 --- a/arch/sim/src/sim/sim_heap.c +++ b/arch/sim/src/sim/sim_heap.c @@ -375,8 +375,7 @@ void *mm_realloc(struct mm_heap_s *heap, void *oldmem, if (size == 0) { - mm_free(heap, oldmem); - return NULL; + size = 1; } oldsize = host_mallocsize(oldmem);