From c13b03604f4b5ac7067b0bc433ccc70b46370106 Mon Sep 17 00:00:00 2001 From: rewine <1758075541@qq.com> Date: Tue, 7 Jun 2022 23:57:18 +0800 Subject: [PATCH] [kernel][mem.c] tighten size before check with mem_size_aligned --- src/mem.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mem.c b/src/mem.c index 4261229256..307391cac1 100644 --- a/src/mem.c +++ b/src/mem.c @@ -299,6 +299,10 @@ void *rt_smem_alloc(rt_smem_t m, rt_size_t size) /* alignment size */ size = RT_ALIGN(size, RT_ALIGN_SIZE); + /* every data block must be at least MIN_SIZE_ALIGNED long */ + if (size < MIN_SIZE_ALIGNED) + size = MIN_SIZE_ALIGNED; + if (size > small_mem->mem_size_aligned) { RT_DEBUG_LOG(RT_DEBUG_MEM, ("no memory\n")); @@ -306,10 +310,6 @@ void *rt_smem_alloc(rt_smem_t m, rt_size_t size) return RT_NULL; } - /* every data block must be at least MIN_SIZE_ALIGNED long */ - if (size < MIN_SIZE_ALIGNED) - size = MIN_SIZE_ALIGNED; - for (ptr = (rt_uint8_t *)small_mem->lfree - small_mem->heap_ptr; ptr <= small_mem->mem_size_aligned - size; ptr = ((struct rt_small_mem_item *)&small_mem->heap_ptr[ptr])->next) -- GitLab