Merge pull request #2823 from Guozhanxin/mempool_test

[src/mempool.c] add parameter check.|添加参数检查。
This commit is contained in:
Bernard Xiong 2019-07-01 19:41:09 +08:00 committed by GitHub
commit 61e4140db2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

View File

@ -85,6 +85,9 @@ rt_err_t rt_mp_init(struct rt_mempool *mp,
/* parameter check */ /* parameter check */
RT_ASSERT(mp != RT_NULL); RT_ASSERT(mp != RT_NULL);
RT_ASSERT(name != RT_NULL);
RT_ASSERT(start != RT_NULL);
RT_ASSERT(size > 0 && block_size > 0);
/* initialize object */ /* initialize object */
rt_object_init(&(mp->parent), RT_Object_Class_MemPool, name); 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; RT_DEBUG_NOT_IN_INTERRUPT;
/* parameter check */
RT_ASSERT(name != RT_NULL);
RT_ASSERT(block_count > 0 && block_size > 0);
/* allocate object */ /* allocate object */
mp = (struct rt_mempool *)rt_object_allocate(RT_Object_Class_MemPool, name); mp = (struct rt_mempool *)rt_object_allocate(RT_Object_Class_MemPool, name);
/* allocate object failed */ /* allocate object failed */
@ -308,6 +315,9 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
struct rt_thread *thread; struct rt_thread *thread;
rt_uint32_t before_sleep = 0; rt_uint32_t before_sleep = 0;
/* parameter check */
RT_ASSERT(mp != RT_NULL);
/* get current thread */ /* get current thread */
thread = rt_thread_self(); thread = rt_thread_self();
@ -402,6 +412,9 @@ void rt_mp_free(void *block)
struct rt_thread *thread; struct rt_thread *thread;
register rt_base_t level; register rt_base_t level;
/* parameter check */
if (block == RT_NULL) return;
/* get the control block of pool which the block belongs to */ /* get the control block of pool which the block belongs to */
block_ptr = (rt_uint8_t **)((rt_uint8_t *)block - sizeof(rt_uint8_t *)); block_ptr = (rt_uint8_t **)((rt_uint8_t *)block - sizeof(rt_uint8_t *));
mp = (struct rt_mempool *)*block_ptr; mp = (struct rt_mempool *)*block_ptr;