+added friendly error promption when memory overflow.
This commit is contained in:
parent
c1705c6a54
commit
25d76bb579
1
HISTORY
1
HISTORY
@ -1,4 +1,5 @@
|
||||
Jan. 26 2016
|
||||
Added friendly error promption when memory overflow
|
||||
Added source file information to stepped handler
|
||||
Optimized cached list accessing
|
||||
|
||||
|
@ -1078,7 +1078,7 @@ static int _ht_remove_exist(void* data, void* extra, _ht_node_t* ht);
|
||||
} while(0)
|
||||
|
||||
/** Memory manipulations */
|
||||
#define _MB_CHECK_MEM_TAG_SIZE(y, s) do { mb_mem_tag_t _tmp = (mb_mem_tag_t)s; if((y)_tmp != s) { mb_assert(0 && "\"mb_mem_tag_t\" is too small."); printf("The type \"mb_mem_tag_t\" is not precise enough to hold the given data, please redefine it!"); } } while(0)
|
||||
#define _MB_CHECK_MEM_TAG_SIZE(y, s) ((mb_mem_tag_t)(s) == (s))
|
||||
#define _MB_WRITE_MEM_TAG_SIZE(t, s) (*((mb_mem_tag_t*)((char*)(t) - _MB_MEM_TAG_SIZE)) = (mb_mem_tag_t)s)
|
||||
#define _MB_READ_MEM_TAG_SIZE(t) (*((mb_mem_tag_t*)((char*)(t) - _MB_MEM_TAG_SIZE)))
|
||||
|
||||
@ -2625,7 +2625,8 @@ void* mb_malloc(size_t s) {
|
||||
char* ret = NULL;
|
||||
size_t rs = s;
|
||||
#ifdef MB_ENABLE_ALLOC_STAT
|
||||
_MB_CHECK_MEM_TAG_SIZE(size_t, s);
|
||||
if(!_MB_CHECK_MEM_TAG_SIZE(size_t, s))
|
||||
return 0;
|
||||
rs += _MB_MEM_TAG_SIZE;
|
||||
#endif /* MB_ENABLE_ALLOC_STAT */
|
||||
if(_mb_allocate_func)
|
||||
|
12
shell/main.c
12
shell/main.c
@ -317,7 +317,11 @@ static char* _pop_mem(unsigned s) {
|
||||
} else {
|
||||
/* Create a new node */
|
||||
result = _POOL_NODE_ALLOC(pl->size);
|
||||
_POOL_NODE_SIZE(result) = (_pool_chunk_size_t)s;
|
||||
if((intptr_t)result == sizeof(_pool_tag_t)) {
|
||||
result = 0;
|
||||
} else {
|
||||
_POOL_NODE_SIZE(result) = (_pool_chunk_size_t)s;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -327,7 +331,11 @@ static char* _pop_mem(unsigned s) {
|
||||
|
||||
/* Allocate directly */
|
||||
result = _POOL_NODE_ALLOC(s);
|
||||
_POOL_NODE_SIZE(result) = (_pool_chunk_size_t)s;
|
||||
if((intptr_t)result == sizeof(_pool_tag_t)) {
|
||||
result = 0;
|
||||
} else {
|
||||
_POOL_NODE_SIZE(result) = (_pool_chunk_size_t)s;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user