Skip to content

Commit b4f93ef

Browse files
committed
Extra cautious DCFlushRange usage for smartAlloc memory
smartAlloc doesn't actually clear the memory that it allocates, so this is just to be extra safe.
1 parent f6b7d2c commit b4f93ef

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ttyd-tools/rel/source/memcard.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "commonfunctions.h"
44

55
#include <gc/card.h>
6+
#include <gc/OSCache.h>
67
#include <ttyd/cardmgr.h>
78
#include <ttyd/memory.h>
89

@@ -153,7 +154,7 @@ int32_t createSettingsFile(int32_t memoryCardSlot, gc::card::CARDFileInfo *setti
153154
tempTotalCustomStates = CUSTOM_STATES_MAX_COUNT;
154155
}
155156

156-
FileSize += tempTotalCustomStates * sizeof(CustomStateStruct);
157+
FileSize += sizeof(CustomStateStruct) * tempTotalCustomStates;
157158
}
158159

159160
// Adjust the file size to be in multiples of CARD_WRITE_SIZE, rounding up
@@ -505,6 +506,9 @@ int32_t loadSettings(int32_t memoryCardSlot)
505506
char *MiscData = reinterpret_cast<char *>(SmartData->pMemory);
506507
clearMemory(MiscData, FileSizeAdjusted);
507508

509+
// Be 100% certain that no memory issues occur, since the allocated memory wasn't cleared automatically
510+
gc::OSCache::DCFlushRange(MiscData, FileSizeAdjusted);
511+
508512
// Get the data from the file
509513
// Must read by the stored size, as the struct size may exceed the size of the file
510514
ReturnCode = readFromFileOnCard(memoryCardSlot, &FileInfo, MiscData, StoredFileSizeAdjusted, 0x2200);

0 commit comments

Comments
 (0)