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:
zik.saleeba 2009-03-11 01:59:22 +00:00
parent 8d315824b5
commit d48345a9ea

7
heap.c
View file

@ -94,13 +94,18 @@ void *HeapAlloc(int Size)
struct AllocNode *NewMem = NULL;
struct AllocNode **FreeNode;
int AllocSize = MEM_ALIGN(Size) + sizeof(NewMem->Size);
int Bucket = AllocSize >> 2;
int Bucket;
if (Size == 0)
return NULL;
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)
{ /* try to allocate from a freelist bucket first */
#ifdef DEBUG_HEAP