Prevent corrupted heaps causing infinite loops

This commit is contained in:
Martin Griffin 2023-07-14 13:27:50 +01:00
parent 4637d7e7ee
commit 25986be089

View File

@ -223,6 +223,15 @@ void CB2_TestRunner(void)
const struct MemBlock *block = head; const struct MemBlock *block = head;
do do
{ {
if (block->magic != MALLOC_SYSTEM_ID
|| !(EWRAM_START <= (uintptr_t)block->next && (uintptr_t)block->next < EWRAM_END)
|| (block->next <= block && block->next != head))
{
MgbaPrintf_("gHeap corrupted block at 0x%p", block);
gTestRunnerState.result = TEST_RESULT_ERROR;
break;
}
if (block->allocated) if (block->allocated)
{ {
const char *location = MemBlockLocation(block); const char *location = MemBlockLocation(block);
@ -495,6 +504,7 @@ static s32 MgbaVPrintf_(const char *fmt, va_list va)
{ {
s32 i = 0; s32 i = 0;
s32 c, d; s32 c, d;
u32 p;
const char *s; const char *s;
while (*fmt) while (*fmt)
{ {
@ -528,6 +538,20 @@ static s32 MgbaVPrintf_(const char *fmt, va_list va)
i = MgbaPutchar_(i, buffer[--n]); i = MgbaPutchar_(i, buffer[--n]);
} }
break; break;
case 'p':
p = va_arg(va, unsigned);
{
s32 n;
for (n = 0; n < 7; n++)
{
unsigned nybble = (p >> (24 - (4*n))) & 0xF;
if (nybble <= 9)
i = MgbaPutchar_(i, '0' + nybble);
else
i = MgbaPutchar_(i, 'a' + nybble - 10);
}
}
break;
case 'q': case 'q':
d = va_arg(va, int); d = va_arg(va, int);
{ {