Safety check for bucket sizes
git-svn-id: http://picoc.googlecode.com/svn/trunk@191 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
8d315824b5
commit
d48345a9ea
7
heap.c
7
heap.c
|
@ -94,13 +94,18 @@ void *HeapAlloc(int Size)
|
||||||
struct AllocNode *NewMem = NULL;
|
struct AllocNode *NewMem = NULL;
|
||||||
struct AllocNode **FreeNode;
|
struct AllocNode **FreeNode;
|
||||||
int AllocSize = MEM_ALIGN(Size) + sizeof(NewMem->Size);
|
int AllocSize = MEM_ALIGN(Size) + sizeof(NewMem->Size);
|
||||||
int Bucket = AllocSize >> 2;
|
int Bucket;
|
||||||
|
|
||||||
if (Size == 0)
|
if (Size == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
assert(Size > 0);
|
assert(Size > 0);
|
||||||
|
|
||||||
|
/* make sure we have enough space for an AllocNode */
|
||||||
|
if (AllocSize < sizeof(struct AllocNode))
|
||||||
|
AllocSize = sizeof(struct AllocNode);
|
||||||
|
|
||||||
|
Bucket = AllocSize >> 2;
|
||||||
if (Bucket < FREELIST_BUCKETS && FreeListBucket[Bucket] != NULL)
|
if (Bucket < FREELIST_BUCKETS && FreeListBucket[Bucket] != NULL)
|
||||||
{ /* try to allocate from a freelist bucket first */
|
{ /* try to allocate from a freelist bucket first */
|
||||||
#ifdef DEBUG_HEAP
|
#ifdef DEBUG_HEAP
|
||||||
|
|
Loading…
Reference in a new issue