From 8d315824b5d64783f33101de3dc2864f7cf45a99 Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Tue, 10 Mar 2009 23:32:36 +0000 Subject: [PATCH] Fixed a problem with heap allocation when splitting large blocks from the free list git-svn-id: http://picoc.googlecode.com/svn/trunk@190 21eae674-98b7-11dd-bd71-f92a316d2d60 --- heap.c | 2 +- table.c | 3 --- variable.c | 4 ++-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/heap.c b/heap.c index 10b0a61..c10f6fc 100644 --- a/heap.c +++ b/heap.c @@ -135,7 +135,7 @@ void *HeapAlloc(int Size) #ifdef DEBUG_HEAP printf("allocating %d(%d) from freelist, split chunk (%d)", Size, AllocSize, (*FreeNode)->Size); #endif - NewMem = *FreeNode + (*FreeNode)->Size - AllocSize; + NewMem = (void *)*FreeNode + (*FreeNode)->Size - AllocSize; assert((unsigned long)NewMem >= (unsigned long)&HeapMemory[0] && (unsigned char *)NewMem - &HeapMemory[0] < HEAP_SIZE); (*FreeNode)->Size -= AllocSize; NewMem->Size = AllocSize; diff --git a/table.c b/table.c index 61dbfff..24d8f7c 100644 --- a/table.c +++ b/table.c @@ -114,9 +114,6 @@ char *TableSetIdentifier(struct Table *Tbl, const char *Ident, int IdentLen) else { /* add it to the table - we economise by not allocating the whole structure here */ struct TableEntry *NewEntry = HeapAlloc(sizeof(struct TableEntry *) + IdentLen + 1); - //printf("allocated 0x%lx:%d for '", (unsigned long)NewEntry, sizeof(struct TableEntry *) + IdentLen + 1); - //fwrite(Ident, 1, IdentLen, stdout); - //printf("'\n"); if (NewEntry == NULL) ProgramFail(NULL, "out of memory"); diff --git a/variable.c b/variable.c index ec5319d..c5f0947 100644 --- a/variable.c +++ b/variable.c @@ -149,8 +149,8 @@ void VariableStackPop(struct ParseState *Parser, struct Value *Var) int Success; #ifdef DEBUG_HEAP - if (Var->ValOnStack) - printf("popping %d at 0x%lx\n", sizeof(struct Value) + VariableSizeValue(Var), (unsigned long)Var); +// if (Var->ValOnStack) +// printf("popping %d at 0x%lx\n", sizeof(struct Value) + VariableSizeValue(Var), (unsigned long)Var); #endif if (Var->ValOnHeap)