FolderMemoryCard: Fix sneaky bug that could occur in directories with odd number of files.

It was possible for an invalid (because never written to, so filled with 0xFF) file entry to be recognized as valid in GetFileEntryPointer(), which cascaded up to it flushing file data as fileEntryDict data and thus losing the relevant file data page.

Not sure if the other two entry accesses changed here are affected as well but better be safe than sorry, I suppose.
This commit is contained in:
Admiral H. Curtiss 2015-05-31 19:00:28 +02:00
parent 7e194f1a26
commit 5f8391f9f1
1 changed files with 3 additions and 3 deletions

View File

@ -520,7 +520,7 @@ u8* FolderMemoryCard::GetFileEntryPointer( const u32 currentCluster, const u32 s
// check subdirectories // check subdirectories
for ( int i = 0; i < 2; ++i ) { for ( int i = 0; i < 2; ++i ) {
MemoryCardFileEntry* const entry = &m_fileEntryDict[currentCluster].entries[i]; MemoryCardFileEntry* const entry = &m_fileEntryDict[currentCluster].entries[i];
if ( entry->IsUsed() && entry->IsDir() && entry->entry.data.cluster != 0 ) { if ( entry->IsValid() && entry->IsUsed() && entry->IsDir() && entry->entry.data.cluster != 0 ) {
u8* ptr = GetFileEntryPointer( entry->entry.data.cluster, searchCluster, entryNumber, offset ); u8* ptr = GetFileEntryPointer( entry->entry.data.cluster, searchCluster, entryNumber, offset );
if ( ptr != nullptr ) { return ptr; } if ( ptr != nullptr ) { return ptr; }
} }
@ -533,7 +533,7 @@ MemoryCardFileEntry* FolderMemoryCard::GetFileEntryFromFileDataCluster( const u3
// check both entries of the current cluster if they're the file we're searching for, and if yes return it // check both entries of the current cluster if they're the file we're searching for, and if yes return it
for ( int i = 0; i < 2; ++i ) { for ( int i = 0; i < 2; ++i ) {
MemoryCardFileEntry* const entry = &m_fileEntryDict[currentCluster].entries[i]; MemoryCardFileEntry* const entry = &m_fileEntryDict[currentCluster].entries[i];
if ( entry->IsUsed() && entry->IsFile() ) { if ( entry->IsValid() && entry->IsUsed() && entry->IsFile() ) {
u32 fileCluster = entry->entry.data.cluster; u32 fileCluster = entry->entry.data.cluster;
u32 clusterNumber = 0; u32 clusterNumber = 0;
do { do {
@ -563,7 +563,7 @@ MemoryCardFileEntry* FolderMemoryCard::GetFileEntryFromFileDataCluster( const u3
// check subdirectories // check subdirectories
for ( int i = 0; i < 2; ++i ) { for ( int i = 0; i < 2; ++i ) {
MemoryCardFileEntry* const entry = &m_fileEntryDict[currentCluster].entries[i]; MemoryCardFileEntry* const entry = &m_fileEntryDict[currentCluster].entries[i];
if ( entry->IsUsed() && entry->IsDir() && entry->entry.data.cluster != 0 ) { if ( entry->IsValid() && entry->IsUsed() && entry->IsDir() && entry->entry.data.cluster != 0 ) {
MemoryCardFileEntry* ptr = GetFileEntryFromFileDataCluster( entry->entry.data.cluster, searchCluster, fileName, originalDirCount, outClusterNumber ); MemoryCardFileEntry* ptr = GetFileEntryFromFileDataCluster( entry->entry.data.cluster, searchCluster, fileName, originalDirCount, outClusterNumber );
if ( ptr != nullptr ) { if ( ptr != nullptr ) {
fileName->InsertDir( originalDirCount, wxString::FromAscii( (const char*)entry->entry.data.name ) ); fileName->InsertDir( originalDirCount, wxString::FromAscii( (const char*)entry->entry.data.name ) );