@@ -382,68 +382,32 @@ uint32_t Mod::pauseArtAttackTimer()
382
382
return mPFN_scissor_timer_main_trampoline ();
383
383
}
384
384
385
- void clearHeapArray ( const char **heap )
385
+ void addTextToHeapArray ( char *text )
386
386
{
387
- uint32_t Counter = 0 ;
388
- while (heap[Counter])
389
- {
390
- delete[] heap[Counter];
391
- heap[Counter] = nullptr ;
392
- Counter++;
393
- }
394
- }
395
-
396
- void addTextToHeapArray (const char **heap, char *text)
397
- {
398
- // Get the next available slot in the array
399
- uint32_t TotalSlots = 16 ;
400
- int32_t FreeSlot = -1 ;
387
+ char *tempHeapBuffer = HeapBuffer;
401
388
402
- for (uint32_t i = 0 ; i < TotalSlots; i++)
403
- {
404
- if (!heap[i])
405
- {
406
- FreeSlot = i;
407
- break ;
408
- }
409
- }
389
+ // Make sure adding the new text will not result in an overflow
390
+ uint32_t NewTextSize = ttyd::string::strlen (text);
391
+ uint32_t CurrentHeapSize = ttyd::string::strlen (tempHeapBuffer);
410
392
411
- // Make sure the new text can be added
412
- if (FreeSlot == -1 )
393
+ uint32_t NewHeapSize = CurrentHeapSize + NewTextSize + 1 ;
394
+ uint32_t MaxHeapSize = sizeof (HeapBuffer);
395
+
396
+ if (NewHeapSize > MaxHeapSize)
413
397
{
414
- // The new text cannot be added
398
+ // Adding the new text will result in an overflow, so don't add it
415
399
return ;
416
400
}
417
401
418
- // Add the new text at the current free slot
419
- uint32_t TextSize = ttyd::string::strlen (text);
420
- char *NewText = new char [TextSize + 1 ];
421
- ttyd::string::strcpy (NewText, text);
422
- heap[FreeSlot] = NewText;
423
- }
424
-
425
- bool checkIfTextAlreadyAdded (const char **heap, const char *text, uint32_t bytesToCompare)
426
- {
427
- uint32_t Counter = 0 ;
428
- while (heap[Counter])
429
- {
430
- if (compareStringsSize (heap[Counter], text, bytesToCompare))
431
- {
432
- return true ;
433
- }
434
- Counter++;
435
- }
436
- return false ;
402
+ // Add the new text onto the heap
403
+ ttyd::string::strcat (tempHeapBuffer, text);
437
404
}
438
405
439
406
void checkHeaps ()
440
407
{
441
- const char **tempStandardHeapArray = CheckHeap.StandardHeapArray ;
442
- const char **tempSmartHeapArray = CheckHeap.SmartHeapArray ;
443
408
char *tempDisplayBuffer = DisplayBuffer;
444
409
445
410
// Check the standard heaps
446
- bool ErrorsFound = false ;
447
411
for (int32_t i = 0 ; i < 5 ; i++)
448
412
{
449
413
const gc::os::HeapInfo &heap = gc::os::OSAlloc_HeapArray[i];
@@ -456,23 +420,20 @@ void checkHeaps()
456
420
// Check pointer sanity
457
421
if (!checkIfPointerIsValid (currentChunk))
458
422
{
459
- ErrorsFound = true ;
460
423
valid = false ;
461
424
break ;
462
425
}
463
426
464
427
// Sanity check size
465
428
if (currentChunk->size > 0x17FFFFF )
466
429
{
467
- ErrorsFound = true ;
468
430
valid = false ;
469
431
break ;
470
432
}
471
433
472
434
// Check linked list integrity
473
435
if (prevChunk != currentChunk->prev )
474
436
{
475
- ErrorsFound = true ;
476
437
valid = false ;
477
438
break ;
478
439
}
@@ -483,24 +444,15 @@ void checkHeaps()
483
444
if (!valid)
484
445
{
485
446
sprintf (tempDisplayBuffer,
486
- " Standard Heap %" PRId32 " corrupted at 0x%08" PRIX32,
447
+ " Standard Heap %" PRId32 " corrupted at 0x%08" PRIX32 " \n " ,
487
448
i,
488
449
reinterpret_cast <uint32_t >(currentChunk));
489
450
490
- // Only add the current heap once
491
- if (!checkIfTextAlreadyAdded (tempStandardHeapArray, tempDisplayBuffer, 16 ))
492
- {
493
- addTextToHeapArray (tempStandardHeapArray, tempDisplayBuffer);
494
- }
451
+ // Add the text to the heap buffer
452
+ addTextToHeapArray (tempDisplayBuffer);
495
453
}
496
454
}
497
455
498
- if (!ErrorsFound)
499
- {
500
- // No errors were found, so clear the standard heap array
501
- clearHeapArray (tempStandardHeapArray);
502
- }
503
-
504
456
// Check the smart heap
505
457
ttyd::memory::SmartWork *gpSmartWork = *reinterpret_cast <ttyd::memory::SmartWork **>(SmartWorkAddress);
506
458
bool valid = true ;
@@ -536,23 +488,15 @@ void checkHeaps()
536
488
if (!valid)
537
489
{
538
490
sprintf (tempDisplayBuffer,
539
- " Smart Heap corrupted at 0x%08" PRIX32,
491
+ " Smart Heap corrupted at 0x%08" PRIX32 " \n " ,
540
492
reinterpret_cast <uint32_t >(currentChunk));
541
493
542
- // Only add the current heap once
543
- if (!checkIfTextAlreadyAdded (tempSmartHeapArray, tempDisplayBuffer, 16 ))
544
- {
545
- addTextToHeapArray (tempSmartHeapArray, tempDisplayBuffer);
546
- }
547
- }
548
- else
549
- {
550
- // No errors were found, so clear the smart heap array
551
- clearHeapArray (tempSmartHeapArray);
494
+ // Add the text to the heap buffer
495
+ addTextToHeapArray (tempDisplayBuffer);
552
496
}
553
497
554
498
// Draw any errors that occured
555
- if (tempStandardHeapArray [0 ] || tempSmartHeapArray[ 0 ] )
499
+ if (HeapBuffer [0 ] != ' \0 ' )
556
500
{
557
501
drawFunctionOnDebugLayer (drawHeapArrayErrors);
558
502
}
0 commit comments