From 5f8391f9f16d11043897c5c8e16a1fd71224364a Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sun, 31 May 2015 19:00:28 +0200 Subject: [PATCH] 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. --- pcsx2/gui/MemoryCardFolder.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pcsx2/gui/MemoryCardFolder.cpp b/pcsx2/gui/MemoryCardFolder.cpp index 4effb15702..de815c6ea1 100644 --- a/pcsx2/gui/MemoryCardFolder.cpp +++ b/pcsx2/gui/MemoryCardFolder.cpp @@ -520,7 +520,7 @@ u8* FolderMemoryCard::GetFileEntryPointer( const u32 currentCluster, const u32 s // check subdirectories for ( int i = 0; i < 2; ++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 ); 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 for ( int i = 0; i < 2; ++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 clusterNumber = 0; do { @@ -563,7 +563,7 @@ MemoryCardFileEntry* FolderMemoryCard::GetFileEntryFromFileDataCluster( const u3 // check subdirectories for ( int i = 0; i < 2; ++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 ); if ( ptr != nullptr ) { fileName->InsertDir( originalDirCount, wxString::FromAscii( (const char*)entry->entry.data.name ) );