Usermode/libc - Exit on heap corruption
[tpg/acess2.git] / Usermode / Libraries / libc.so_src / heap.c
index d529f65..1c0c7ac 100644 (file)
@@ -94,13 +94,16 @@ EXPORT void *malloc(size_t bytes)
                        //Corrupt Heap\r
                        Heap_Dump();\r
                        _SysDebug("malloc: Corrupt Heap\n");\r
+                       exit(128);\r
                        return NULL;\r
                }\r
                curBlock = (heap_head*)((uintptr_t)curBlock + curBlock->size);\r
        }\r
        \r
        if((uintptr_t)curBlock < (uintptr_t)_heap_start) {\r
+               Heap_Dump();\r
                _SysDebug("malloc: Heap underrun for some reason\n");\r
+               exit(128);\r
                return NULL;\r
        }\r
        \r
@@ -185,7 +188,7 @@ EXPORT void free(void *mem)
        DEBUGS("free(%p) : 0x%x bytes", mem, head->size);\r
        \r
        //Unify Right\r
-       if((intptr_t)head + head->size < (intptr_t)_heap_end)\r
+       if((uintptr_t)head + head->size < (uintptr_t)_heap_end)\r
        {\r
                heap_head       *nextHead = (heap_head*)((intptr_t)head + head->size);\r
                if(nextHead->magic == MAGIC_FREE) {     //Is the next block free\r
@@ -194,7 +197,7 @@ EXPORT void free(void *mem)
                }\r
        }\r
        //Unify Left\r
-       if((intptr_t)head - sizeof(heap_foot) > (intptr_t)_heap_start)\r
+       if((uintptr_t)head - sizeof(heap_foot) > (uintptr_t)_heap_start)\r
        {\r
                heap_head       *prevHead;\r
                heap_foot       *prevFoot = (heap_foot *)((intptr_t)head - sizeof(heap_foot));\r

UCC git Repository :: git.ucc.asn.au