From: Michael D. Lowis Date: Fri, 22 Aug 2014 02:29:04 +0000 (-0400) Subject: Added asserts to mem X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=b840dfdf5e4bcbc7122c5856e57340eeec86d055;p=projs%2Flibcds.git Added asserts to mem --- diff --git a/source/mem/mem.c b/source/mem/mem.c index 643219b..feb8c80 100644 --- a/source/mem/mem.c +++ b/source/mem/mem.c @@ -1,5 +1,6 @@ #include "mem.h" #include +#include #ifdef LEAK_DETECT_LEVEL #include #include @@ -139,20 +140,26 @@ void* mem_allocate(size_t size, destructor_t p_destruct_fn) int mem_num_references(void* p_obj) { - obj_t* p_hdr = (((obj_t*)p_obj)-1); + obj_t* p_hdr; + assert(NULL != p_obj); + p_hdr = (((obj_t*)p_obj)-1); return p_hdr->refcount; } void* mem_retain(void* p_obj) { - obj_t* p_hdr = (((obj_t*)p_obj)-1); + obj_t* p_hdr; + assert(NULL != p_obj); + p_hdr = (((obj_t*)p_obj)-1); p_hdr->refcount += 1; return p_obj; } void mem_release(void* p_obj) { - obj_t* p_hdr = (((obj_t*)p_obj)-1); + obj_t* p_hdr; + assert(NULL != p_obj); + p_hdr = (((obj_t*)p_obj)-1); p_hdr->refcount -= 1; if(p_hdr->refcount < 1) { @@ -178,6 +185,7 @@ void* mem_box(intptr_t val) intptr_t mem_unbox(void* p_box) { + assert(NULL != p_box); return ((box_t*)p_box)->val; }