summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorguozhanxin <[email protected]>2019-07-01 12:55:10 +0800
committerguozhanxin <[email protected]>2019-07-01 12:56:12 +0800
commit5e6f852cbe3c2e19a66f4847b69466ab9bfefcf3 (patch)
treedc00ec96e9a71fccc82a8494243e572a0af85203
parent2c9fec5692f843c136a8cf84e209b53f3a6a8bee (diff)
[src/mempool.c] add parameter check.|添加参数检查。
-rw-r--r--src/mempool.c13
1 files changed, 13 insertions, 0 deletions
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;