From 4e09aeb3a8e5f89cbaa169b7062861a139d03d6c Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Mon, 8 Jul 2019 10:17:30 +0200 Subject: [PATCH] pfile: add assert comments to pfile_rename_temp_to_perm Based on @galaxyhaxz code in https://github.com/diasurgical/devilution/pull/1294#issuecomment-509018789 Also, per suggestion of @sskras. --- Source/pfile.cpp | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/Source/pfile.cpp b/Source/pfile.cpp index 1d28e9fe9..8da2e20ac 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -566,27 +566,31 @@ BOOL __stdcall GetTempSaveNames(DWORD dwIndex, char *szTemp) void pfile_rename_temp_to_perm() { - DWORD save_num, i; - char TempName[MAX_PATH]; - char PermName[MAX_PATH]; - - save_num = pfile_get_save_num_from_name(plr[myplr]._pName); - if (!pfile_open_archive(FALSE, save_num)) + DWORD dwChar, dwIndex; + BOOL bResult; + char szTemp[MAX_PATH]; + char szPerm[MAX_PATH]; + + dwChar = pfile_get_save_num_from_name(plr[myplr]._pName); + /// ASSERT: assert(dwChar < MAX_CHARACTERS); + /// ASSERT: assert(gbMaxPlayers == 1); + if (!pfile_open_archive(FALSE, dwChar)) app_fatal("Unable to write to save file archive"); - i = 0; - while (GetTempSaveNames(i, TempName)) { - GetPermSaveNames(i, PermName); - i++; - if (mpqapi_has_file(TempName)) { - if (mpqapi_has_file(PermName)) - mpqapi_remove_hash_entry(PermName); - mpqapi_rename(TempName, PermName); + dwIndex = 0; + while (GetTempSaveNames(dwIndex, szTemp)) { + bResult = GetPermSaveNames(dwIndex, szPerm); + /// ASSERT: assert(bResult); + dwIndex++; + if (mpqapi_has_file(szTemp)) { + if (mpqapi_has_file(szPerm)) + mpqapi_remove_hash_entry(szPerm); + mpqapi_rename(szTemp, szPerm); } } - // BUGFIX: function call has no purpose - GetPermSaveNames(i, PermName); - pfile_flush(TRUE, save_num); + /// ASSERT: assert(! GetPermSaveNames(dwIndex,szPerm)); + GetPermSaveNames(dwIndex, szPerm); + pfile_flush(TRUE, dwChar); } BOOL __stdcall GetPermSaveNames(DWORD dwIndex, char *szPerm)