From 5e6f852cbe3c2e19a66f4847b69466ab9bfefcf3 Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Mon, 1 Jul 2019 12:55:10 +0800 Subject: [PATCH] =?UTF-8?q?[src/mempool.c]=20add=20parameter=20check.|?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=82=E6=95=B0=E6=A3=80=E6=9F=A5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mempool.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/mempool.c b/src/mempool.c index 2184586aba..6b1fc81231 100644 --- a/src/mempool.c +++ b/src/mempool.c @@ -85,6 +85,9 @@ rt_err_t rt_mp_init(struct rt_mempool *mp, /* parameter check */ RT_ASSERT(mp != RT_NULL); + RT_ASSERT(name != RT_NULL); + RT_ASSERT(start != RT_NULL); + RT_ASSERT(size > 0 && block_size > 0); /* initialize object */ rt_object_init(&(mp->parent), RT_Object_Class_MemPool, name); @@ -192,6 +195,10 @@ rt_mp_t rt_mp_create(const char *name, RT_DEBUG_NOT_IN_INTERRUPT; + /* parameter check */ + RT_ASSERT(name != RT_NULL); + RT_ASSERT(block_count > 0 && block_size > 0); + /* allocate object */ mp = (struct rt_mempool *)rt_object_allocate(RT_Object_Class_MemPool, name); /* allocate object failed */ @@ -308,6 +315,9 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time) struct rt_thread *thread; rt_uint32_t before_sleep = 0; + /* parameter check */ + RT_ASSERT(mp != RT_NULL); + /* get current thread */ thread = rt_thread_self(); @@ -402,6 +412,9 @@ void rt_mp_free(void *block) struct rt_thread *thread; register rt_base_t level; + /* parameter check */ + if (block == RT_NULL) return; + /* get the control block of pool which the block belongs to */ block_ptr = (rt_uint8_t **)((rt_uint8_t *)block - sizeof(rt_uint8_t *)); mp = (struct rt_mempool *)*block_ptr;