Misc: Fix a bunch of code analysis warnings

Some of which were even actual errors.
This commit is contained in:
Stenzek
2024-08-02 23:56:06 +10:00
parent 4eb3b2a9a7
commit 3a83c4265c
30 changed files with 93 additions and 78 deletions

View File

@ -351,7 +351,7 @@ std::optional<BIOS::Image> BIOS::FindBIOSImageInDirectory(ConsoleRegion region,
std::string full_path(Path::Combine(directory, fd.FileName));
std::optional<Image> found_image = LoadImageFromFile(full_path.c_str(), nullptr);
if (!found_image)
if (!found_image.has_value())
continue;
if (found_image->info && IsValidBIOSForRegion(region, found_image->info->region))

View File

@ -1399,8 +1399,11 @@ template<MemoryAccessSize size>
u32 Bus::HWHandlers::MemCtrlRead(PhysicalMemoryAddress address)
{
const u32 offset = address & MEMCTRL_MASK;
const u32 index = FIXUP_WORD_OFFSET(size, offset) / 4;
if (index >= std::size(s_MEMCTRL.regs)) [[unlikely]]
return 0;
u32 value = s_MEMCTRL.regs[FIXUP_WORD_OFFSET(size, offset) / 4];
u32 value = s_MEMCTRL.regs[index];
value = FIXUP_WORD_READ_VALUE(size, offset, value);
BUS_CYCLES(2);
return value;
@ -1411,6 +1414,9 @@ void Bus::HWHandlers::MemCtrlWrite(PhysicalMemoryAddress address, u32 value)
{
const u32 offset = address & MEMCTRL_MASK;
const u32 index = FIXUP_WORD_OFFSET(size, offset) / 4;
if (index >= std::size(s_MEMCTRL.regs)) [[unlikely]]
return;
value = FIXUP_WORD_WRITE_VALUE(size, offset, value);
const u32 write_mask = (index == 8) ? COMDELAY::WRITE_MASK : MEMDELAY::WRITE_MASK;
@ -1516,6 +1522,7 @@ u32 Bus::HWHandlers::CDROMRead(PhysicalMemoryAddress address)
const u32 b3 = ZeroExtend32(CDROM::ReadRegister(offset + 3u));
value = b0 | (b1 << 8) | (b2 << 16) | (b3 << 24);
}
break;
case MemoryAccessSize::HalfWord:
{
@ -1523,10 +1530,12 @@ u32 Bus::HWHandlers::CDROMRead(PhysicalMemoryAddress address)
const u32 msb = ZeroExtend32(CDROM::ReadRegister(offset + 1u));
value = lsb | (msb << 8);
}
break;
case MemoryAccessSize::Byte:
default:
value = ZeroExtend32(CDROM::ReadRegister(offset));
break;
}
BUS_CYCLES(Bus::g_cdrom_access_time[static_cast<u32>(size)]);

View File

@ -661,8 +661,10 @@ bool CheatList::LoadFromString(const std::string& str, Format format)
return LoadFromPCSXRString(str);
else if (format == Format::Libretro)
return LoadFromLibretroString(str);
format = Format::EPSXe;
return LoadFromEPSXeString(str);
else if (format == Format::EPSXe)
return LoadFromEPSXeString(str);
else
return false;
}
bool CheatList::SaveToPCSXRFile(const char* filename)
@ -2782,7 +2784,7 @@ const char* CheatCode::GetTypeDisplayName(Type type)
std::optional<CheatCode::Type> CheatCode::ParseTypeName(const char* str)
{
for (u32 i = 0; i < static_cast<u32>(s_cheat_code_type_names.size()); i++)
for (size_t i = 0; i < s_cheat_code_type_names.size(); i++)
{
if (std::strcmp(s_cheat_code_type_names[i], str) == 0)
return static_cast<Type>(i);

View File

@ -1172,7 +1172,7 @@ void FullscreenUI::DoChangeDisc()
if (const GameDatabase::Entry* entry = System::GetGameDatabaseEntry(); entry && !entry->disc_set_serials.empty())
{
const auto lock = GameList::GetLock();
const auto matches = GameList::GetMatchingEntriesForSerial(entry->disc_set_serials);
auto matches = GameList::GetMatchingEntriesForSerial(entry->disc_set_serials);
if (matches.size() > 1)
{
options.reserve(matches.size() + 1);
@ -5759,7 +5759,7 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
if (i == 0)
ResetFocusHere();
const SaveStateListEntry& entry = s_save_state_selector_slots[i];
SaveStateListEntry& entry = s_save_state_selector_slots[i];
if (static_cast<s32>(i) == s_save_state_selector_submenu_index)
{
// can't use a choice dialog here, because we're already in a modal...
@ -6021,7 +6021,7 @@ void FullscreenUI::DrawResumeStateSelector()
if (ImGui::BeginPopupModal(FSUI_CSTR("Load Resume State"), &is_open,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize))
{
const SaveStateListEntry& entry = s_save_state_selector_slots.front();
SaveStateListEntry& entry = s_save_state_selector_slots.front();
SmallString time;
TimeToPrintableString(&time, entry.timestamp);
ImGui::TextWrapped(

View File

@ -1736,10 +1736,10 @@ std::string GameList::GetGameIconPath(std::string_view serial, std::string_view
// Try extracting an icon.
Error error;
MemoryCardImage::DataArray data;
if (MemoryCardImage::LoadFromFile(&data, memcard_path.c_str(), &error))
std::unique_ptr<MemoryCardImage::DataArray> data = std::make_unique<MemoryCardImage::DataArray>();
if (MemoryCardImage::LoadFromFile(data.get(), memcard_path.c_str(), &error))
{
std::vector<MemoryCardImage::FileInfo> files = MemoryCardImage::EnumerateFiles(data, false);
std::vector<MemoryCardImage::FileInfo> files = MemoryCardImage::EnumerateFiles(*data.get(), false);
if (!files.empty())
{
const MemoryCardImage::FileInfo& fi = files.front();

View File

@ -2253,7 +2253,6 @@ void GPU_HW::DrawLine(const GSVector4 bounds, u32 col0, u32 col1, float depth)
const float abs_dx = std::fabs(dx);
const float abs_dy = std::fabs(dy);
float fill_dx, fill_dy;
float dxdk, dydk;
float pad_x0 = 0.0f;
float pad_x1 = 0.0f;
float pad_y0 = 0.0f;
@ -2268,8 +2267,7 @@ void GPU_HW::DrawLine(const GSVector4 bounds, u32 col0, u32 col1, float depth)
{
fill_dx = 0.0f;
fill_dy = 1.0f;
dxdk = 1.0f;
dydk = dy / abs_dx;
const float dydk = dy / abs_dx;
if (dx > 0.0f)
{
@ -2288,8 +2286,7 @@ void GPU_HW::DrawLine(const GSVector4 bounds, u32 col0, u32 col1, float depth)
{
fill_dx = 1.0f;
fill_dy = 0.0f;
dydk = 1.0f;
dxdk = dx / abs_dy;
const float dxdk = dx / abs_dy;
if (dy > 0.0f)
{

View File

@ -239,7 +239,6 @@ void ImGuiManager::DrawPerformanceOverlay()
ImDrawList* dl = ImGui::GetBackgroundDrawList();
SmallString text;
ImVec2 text_size;
bool first = true;
#define DRAW_LINE(font, text, color) \
do \
@ -260,21 +259,16 @@ void ImGuiManager::DrawPerformanceOverlay()
{
const float speed = System::GetEmulationSpeed();
if (g_settings.display_show_fps)
{
text.append_format("G: {:.2f} | V: {:.2f}", System::GetFPS(), System::GetVPS());
first = false;
}
if (g_settings.display_show_speed)
{
text.append_format("{}{}%", first ? "" : " | ", static_cast<u32>(std::round(speed)));
text.append_format("{}{}%", text.empty() ? "" : " | ", static_cast<u32>(std::round(speed)));
const float target_speed = System::GetTargetSpeed();
if (target_speed <= 0.0f)
text.append(" (Max)");
else
text.append_format(" ({:.0f}%)", target_speed * 100.0f);
first = false;
}
if (!text.empty())
{
@ -325,7 +319,7 @@ void ImGuiManager::DrawPerformanceOverlay()
g_settings.cpu_execution_mode != CPUExecutionMode::Recompiler || g_settings.cpu_recompiler_icache ||
g_settings.cpu_recompiler_memory_exceptions)
{
first = true;
bool first = true;
text.assign("CPU[");
if (g_settings.cpu_overclock_active)
{

View File

@ -962,11 +962,11 @@ bool System::ReadExecutableFromImage(CDImage* cdi, std::string* out_executable_n
bool System::ReadExecutableFromImage(IsoReader& iso, std::string* out_executable_name,
std::vector<u8>* out_executable_data)
{
const std::string executable_path = GetExecutableNameForImage(iso, false);
std::string executable_path = GetExecutableNameForImage(iso, false);
DEV_LOG("Executable path: '{}'", executable_path);
if (!executable_path.empty() && out_executable_data)
{
if (!iso.ReadFile(executable_path.c_str(), out_executable_data))
if (!iso.ReadFile(executable_path, out_executable_data))
{
ERROR_LOG("Failed to read executable '{}' from disc", executable_path);
return false;
@ -993,26 +993,31 @@ System::GameHash System::GetGameHashFromBuffer(std::string_view exe_name, std::s
return hash;
}
DiscRegion System::GetRegionForSerial(std::string_view serial)
DiscRegion System::GetRegionForSerial(const std::string_view serial)
{
std::string prefix;
for (size_t pos = 0; pos < serial.length(); pos++)
{
const int ch = std::tolower(serial[pos]);
if (ch < 'a' || ch > 'z')
break;
static constexpr const std::pair<const char*, DiscRegion> region_prefixes[] = {
{"sces", DiscRegion::PAL},
{"sced", DiscRegion::PAL},
{"sles", DiscRegion::PAL},
{"sled", DiscRegion::PAL},
prefix.push_back(static_cast<char>(ch));
{"scps", DiscRegion::NTSC_J},
{"slps", DiscRegion::NTSC_J},
{"slpm", DiscRegion::NTSC_J},
{"sczs", DiscRegion::NTSC_J},
{"papx", DiscRegion::NTSC_J},
{"scus", DiscRegion::NTSC_U},
{"slus", DiscRegion::NTSC_U},
};
for (const auto& [prefix, region] : region_prefixes)
{
if (StringUtil::StartsWithNoCase(serial, prefix))
return region;
}
if (prefix == "sces" || prefix == "sced" || prefix == "sles" || prefix == "sled")
return DiscRegion::PAL;
else if (prefix == "scps" || prefix == "slps" || prefix == "slpm" || prefix == "sczs" || prefix == "papx")
return DiscRegion::NTSC_J;
else if (prefix == "scus" || prefix == "slus")
return DiscRegion::NTSC_U;
else
return DiscRegion::Other;
return DiscRegion::Other;
}
DiscRegion System::GetRegionFromSystemArea(CDImage* cdi)
@ -1311,7 +1316,7 @@ bool System::UpdateGameSettingsLayer()
std::unique_ptr<INISettingsInterface> input_interface;
if (!input_profile_name.empty())
{
const std::string filename(GetInputProfilePath(input_profile_name));
std::string filename = GetInputProfilePath(input_profile_name);
if (FileSystem::FileExists(filename.c_str()))
{
INFO_LOG("Loading input profile from '{}'...", Path::GetFileName(filename));

View File

@ -142,7 +142,7 @@ bool ReadExecutableFromImage(CDImage* cdi, std::string* out_executable_name, std
std::string GetGameHashId(GameHash hash);
bool GetGameDetailsFromImage(CDImage* cdi, std::string* out_id, GameHash* out_hash);
GameHash GetGameHashFromFile(const char* path);
DiscRegion GetRegionForSerial(std::string_view serial);
DiscRegion GetRegionForSerial(const std::string_view serial);
DiscRegion GetRegionFromSystemArea(CDImage* cdi);
DiscRegion GetRegionForImage(CDImage* cdi);
DiscRegion GetRegionForExe(const char* path);

View File

@ -215,6 +215,8 @@ void TextureReplacements::Reload()
void TextureReplacements::PurgeUnreferencedTexturesFromCache()
{
TextureCache old_map = std::move(s_texture_cache);
s_texture_cache = {};
for (const auto& it : s_vram_write_replacements)
{
auto it2 = old_map.find(it.second);