diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp index 8d8cfb77ff..3dd2f5c5e7 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp +++ b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp @@ -289,7 +289,7 @@ const BlockAlloc& GCMemcard::GetActiveBat() const void GCMemcard::UpdateDirectory(const Directory& directory) { // overwrite inactive dir with given data, then set active dir to written block - int new_directory_index = m_active_directory == 0 ? 1 : 0; + const int new_directory_index = m_active_directory == 0 ? 1 : 0; m_directory_blocks[new_directory_index] = directory; m_active_directory = new_directory_index; } @@ -297,7 +297,7 @@ void GCMemcard::UpdateDirectory(const Directory& directory) void GCMemcard::UpdateBat(const BlockAlloc& bat) { // overwrite inactive BAT with given data, then set active BAT to written block - int new_bat_index = m_active_bat == 0 ? 1 : 0; + const int new_bat_index = m_active_bat == 0 ? 1 : 0; m_bat_blocks[new_bat_index] = bat; m_active_bat = new_bat_index; } @@ -333,7 +333,7 @@ static std::pair CalculateMemcardChecksums(const u8* data, size_t size for (size_t i = 0; i < size; i += 2) { - u16 d = Common::swap16(&data[i]); + const u16 d = Common::swap16(&data[i]); csum += d; inv_csum += static_cast(d ^ 0xffff); } @@ -434,7 +434,7 @@ u16 GCMemcard::DEntry_FirstBlock(u8 index) const if (!m_valid || index >= DIRLEN) return 0xFFFF; - u16 block = GetActiveDirectory().m_dir_entries[index].m_first_block; + const u16 block = GetActiveDirectory().m_dir_entries[index].m_first_block; if (block > (u16)m_size_blocks) return 0xFFFF; return block; @@ -445,7 +445,7 @@ u16 GCMemcard::DEntry_BlockCount(u8 index) const if (!m_valid || index >= DIRLEN) return 0xFFFF; - u16 blocks = GetActiveDirectory().m_dir_entries[index].m_block_count; + const u16 blocks = GetActiveDirectory().m_dir_entries[index].m_block_count; if (blocks > (u16)m_size_blocks) return 0xFFFF; return blocks; @@ -594,7 +594,7 @@ bool BlockAlloc::ClearBlocks(u16 starting_block, u16 block_count) } if (starting_block > 0) { - size_t length = blocks.size(); + const size_t length = blocks.size(); if (length != block_count) { return false; @@ -615,7 +615,7 @@ void BlockAlloc::FixChecksums() u16 BlockAlloc::AssignBlocksContiguous(u16 length) { - u16 starting = m_last_allocated_block + 1; + const u16 starting = m_last_allocated_block + 1; if (length > m_free_blocks) return 0xFFFF; u16 current = starting; @@ -753,7 +753,7 @@ GCMemcardImportFileRetVal GCMemcard::ImportFile(const Savefile& savefile) UpdatedDir.m_update_counter = UpdatedDir.m_update_counter + 1; UpdateDirectory(UpdatedDir); - int fileBlocks = direntry.m_block_count; + const int fileBlocks = direntry.m_block_count; std::vector blocks = savefile.blocks; FZEROGX_MakeSaveGameValid(m_header_block, direntry, blocks); @@ -808,8 +808,8 @@ GCMemcardRemoveFileRetVal GCMemcard::RemoveFile(u8 index) // index in the direc if (index >= DIRLEN) return GCMemcardRemoveFileRetVal::DELETE_FAIL; - u16 startingblock = GetActiveDirectory().m_dir_entries[index].m_first_block; - u16 numberofblocks = GetActiveDirectory().m_dir_entries[index].m_block_count; + const u16 startingblock = GetActiveDirectory().m_dir_entries[index].m_first_block; + const u16 numberofblocks = GetActiveDirectory().m_dir_entries[index].m_block_count; BlockAlloc UpdatedBat = GetActiveBat(); if (!UpdatedBat.ClearBlocks(startingblock, numberofblocks)) @@ -953,7 +953,7 @@ std::optional> GCMemcard::ReadAnimRGBA // now that we have determined the data length, fetch the actual data from the save file // if anything is sketchy, bail so we don't access out of bounds - auto save_data_bytes = GetSaveDataBytes(index, image_offset, data_length); + const auto save_data_bytes = GetSaveDataBytes(index, image_offset, data_length); if (!save_data_bytes || save_data_bytes->size() != data_length) return std::nullopt; @@ -1022,9 +1022,9 @@ bool GCMemcard::Format(u8* card_data, const CardFlashId& flash_id, u16 size_mbit if (!card_data) return false; - Header header(flash_id, size_mbits, shift_jis, rtc_bias, sram_language, format_time); - Directory dir; - BlockAlloc bat(size_mbits); + const Header header(flash_id, size_mbits, shift_jis, rtc_bias, sram_language, format_time); + const Directory dir; + const BlockAlloc bat(size_mbits); std::memcpy(&card_data[BLOCK_SIZE * 0], &header, BLOCK_SIZE); std::memcpy(&card_data[BLOCK_SIZE * 1], &dir, BLOCK_SIZE); diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp b/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp index c7be096c75..5698930b19 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp +++ b/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp @@ -45,7 +45,7 @@ static std::string GenerateDefaultGCIFilename(const Memcard::DEntry& entry, { const auto string_decoder = card_encoding_is_shift_jis ? SHIFTJISToUTF8 : CP1252ToUTF8; const auto strip_null = [](const std::string_view& s) { - auto offset = s.find('\0'); + const auto offset = s.find('\0'); if (offset == std::string_view::npos) return s; return s.substr(0, offset); @@ -115,7 +115,7 @@ bool GCMemcardDirectory::LoadGCI(Memcard::GCIFile gci) } // actually load save file into memory card - int idx = (int)m_saves.size(); + const int idx = (int)m_saves.size(); m_dir1.Replace(gci.m_gci_header, idx); m_saves.push_back(std::move(gci)); SetUsedBlocks(idx); @@ -190,7 +190,7 @@ GCMemcardDirectory::GCMemcardDirectory(const std::string& directory, ExpansionIn } const bool current_game_only = Config::Get(Config::SESSION_GCI_FOLDER_CURRENT_GAME_ONLY); - std::vector filenames = Common::DoFileSearch({m_save_directory}, {".gci"}); + const std::vector filenames = Common::DoFileSearch({m_save_directory}, {".gci"}); // split up into files for current games we should definitely load, // and files for other games that we don't care too much about @@ -298,8 +298,8 @@ GCMemcardDirectory::~GCMemcardDirectory() s32 GCMemcardDirectory::Read(u32 src_address, s32 length, u8* dest_address) { - s32 block = src_address / Memcard::BLOCK_SIZE; - u32 offset = src_address % Memcard::BLOCK_SIZE; + const s32 block = src_address / Memcard::BLOCK_SIZE; + const u32 offset = src_address % Memcard::BLOCK_SIZE; s32 extra = 0; // used for read calls that are across multiple blocks if (offset + length > Memcard::BLOCK_SIZE) @@ -358,8 +358,8 @@ s32 GCMemcardDirectory::Write(u32 dest_address, s32 length, const u8* src_addres std::unique_lock l(m_write_mutex); if (length != 0x80) INFO_LOG_FMT(EXPANSIONINTERFACE, "Writing to {:#x}. Length: {:#x}", dest_address, length); - s32 block = dest_address / Memcard::BLOCK_SIZE; - u32 offset = dest_address % Memcard::BLOCK_SIZE; + const s32 block = dest_address / Memcard::BLOCK_SIZE; + const u32 offset = dest_address % Memcard::BLOCK_SIZE; s32 extra = 0; // used for write calls that are across multiple blocks if (offset + length > Memcard::BLOCK_SIZE) @@ -386,7 +386,7 @@ s32 GCMemcardDirectory::Write(u32 dest_address, s32 length, const u8* src_addres s32 bytes_written = 0; while (length > 0) { - s32 to_write = std::min(Memcard::DENTRY_SIZE, length); + const s32 to_write = std::min(Memcard::DENTRY_SIZE, length); bytes_written += DirectoryWrite(dest_address + bytes_written, to_write, src_address + bytes_written); length -= to_write; @@ -536,7 +536,7 @@ inline s32 GCMemcardDirectory::SaveAreaRW(u32 block, bool writing) SetUsedBlocks(i); } - int idx = m_saves[i].UsesBlock(block); + const int idx = m_saves[i].UsesBlock(block); if (idx != -1) { if (!m_saves[i].LoadSaveBlocks()) @@ -565,10 +565,10 @@ inline s32 GCMemcardDirectory::SaveAreaRW(u32 block, bool writing) s32 GCMemcardDirectory::DirectoryWrite(u32 dest_address, u32 length, const u8* src_address) { - u32 block = dest_address / Memcard::BLOCK_SIZE; - u32 offset = dest_address % Memcard::BLOCK_SIZE; + const u32 block = dest_address / Memcard::BLOCK_SIZE; + const u32 offset = dest_address % Memcard::BLOCK_SIZE; Memcard::Directory* dest = (block == 1) ? &m_dir1 : &m_dir2; - u16 Dnum = offset / Memcard::DENTRY_SIZE; + const u16 Dnum = offset / Memcard::DENTRY_SIZE; if (Dnum == Memcard::DIRLEN) { diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcardRaw.cpp b/Source/Core/Core/HW/GCMemcard/GCMemcardRaw.cpp index f5a3f6a8ba..d8a2202b16 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcardRaw.cpp +++ b/Source/Core/Core/HW/GCMemcard/GCMemcardRaw.cpp @@ -60,7 +60,7 @@ MemoryCard::MemoryCard(const std::string& filename, ExpansionInterface::Slot car m_memcard_data = std::make_unique(m_memory_card_size); // Fills in the first 5 blocks (MC_HDR_SIZE bytes) - auto& sram = Core::System::GetInstance().GetSRAM(); + const auto& sram = Core::System::GetInstance().GetSRAM(); const CardFlashId& flash_id = sram.settings_ex.flash_id[Memcard::SLOT_A]; const bool shift_jis = m_filename.find(".JAP.raw") != std::string::npos; const u32 rtc_bias = sram.settings.rtc_bias; @@ -107,10 +107,10 @@ void MemoryCard::FlushThread() { // If triggered, we're exiting. // If timed out, check if we need to flush. - bool do_exit = m_flush_trigger.WaitFor(flush_interval); + const bool do_exit = m_flush_trigger.WaitFor(flush_interval); if (!do_exit) { - bool is_dirty = m_dirty.TestAndClear(); + const bool is_dirty = m_dirty.TestAndClear(); if (!is_dirty) { continue; diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcardRaw.h b/Source/Core/Core/HW/GCMemcard/GCMemcardRaw.h index 3138899667..08ab581caa 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcardRaw.h +++ b/Source/Core/Core/HW/GCMemcard/GCMemcardRaw.h @@ -32,7 +32,7 @@ public: private: bool IsAddressInBounds(u32 address, u32 length) const { - u64 end_address = static_cast(address) + static_cast(length); + const u64 end_address = static_cast(address) + static_cast(length); return end_address <= static_cast(m_memory_card_size); } diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcardUtils.cpp b/Source/Core/Core/HW/GCMemcard/GCMemcardUtils.cpp index e16b452774..c7e0aa06a8 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcardUtils.cpp +++ b/Source/Core/Core/HW/GCMemcard/GCMemcardUtils.cpp @@ -91,7 +91,7 @@ bool HasDuplicateIdentity(std::span savefiles) static void ByteswapDEntrySavHeader(std::array& entry) { // several bytes in SAV are swapped compared to the internal memory card format - for (size_t p : {0x06, 0x2C, 0x2E, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3A, 0x3C, 0x3E}) + for (const size_t p : {0x06, 0x2C, 0x2E, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3A, 0x3C, 0x3E}) std::swap(entry[p], entry[p + 1]); } @@ -304,10 +304,10 @@ bool WriteSavefile(const std::string& filename, const Savefile& savefile, Savefi std::string GenerateFilename(const DEntry& entry) { - std::string maker(reinterpret_cast(entry.m_makercode.data()), - entry.m_makercode.size()); - std::string gamecode(reinterpret_cast(entry.m_gamecode.data()), - entry.m_gamecode.size()); + const std::string maker(reinterpret_cast(entry.m_makercode.data()), + entry.m_makercode.size()); + const std::string gamecode(reinterpret_cast(entry.m_gamecode.data()), + entry.m_gamecode.size()); // prevent going out of bounds when all bytes of m_filename are non-null size_t length = 0; @@ -317,7 +317,7 @@ std::string GenerateFilename(const DEntry& entry) break; ++length; } - std::string filename(reinterpret_cast(entry.m_filename.data()), length); + const std::string filename(reinterpret_cast(entry.m_filename.data()), length); return Common::EscapeFileName(maker + '-' + gamecode + '-' + filename); }