LOCAL void *extendHeap(int bytes);\r
static void *FindHeapBase();\r
LOCAL uint brk(uintptr_t newpos);\r
+LOCAL void Heap_Dump(void);\r
\r
//Code\r
\r
else if(curBlock->magic != MAGIC)\r
{\r
//Corrupt Heap\r
+ Heap_Dump();\r
_SysDebug("malloc: Corrupt Heap\n");\r
return NULL;\r
}\r
\r
return ret; // Return old curpos\r
}\r
+\r
+void Heap_Dump(void)\r
+{\r
+ heap_head *cur = _heap_start;\r
+ while( cur < _heap_end )\r
+ {\r
+ switch( cur->magic )\r
+ {\r
+ case MAGIC:\r
+ _SysDebug("Used block %p[0x%x] - ptr=%p", cur, cur->size, cur->data);\r
+ break;\r
+ case MAGIC_FREE:\r
+ _SysDebug("Free block %p[0x%x] - ptr=%p", cur, cur->size, cur->data);\r
+ break;\r
+ default:\r
+ _SysDebug("Block %p bad magic (0x%x)", cur, cur->magic);\r
+ return ;\r
+ }\r
+ cur = (void*)( (char*)cur + cur->size );\r
+ }\r
+}\r
+\r
char *sp = (char *)src;
char *dp = (char *)dest;
// Check if the areas overlap
- if( (intptr_t)dest > (intptr_t)src && (intptr_t)dest < (intptr_t)src+count )
- for(;count--;) dp[count] = sp[count];
+ if( (intptr_t)src < (intptr_t)dest && (intptr_t)dest < (intptr_t)src+count )
+ for(;count--;)
+ dp[count] = sp[count];
else
- for(;count--;) *dp++ = *sp++;
+ memcpy(dest, src, count);
return dest;
}