Replace find(x) != npos with contains(x) - Core

This commit is contained in:
Dr. Dystopia
2026-04-20 09:36:08 +02:00
parent e235cebb01
commit 9ae9c12938
13 changed files with 38 additions and 44 deletions
+1 -2
View File
@@ -719,8 +719,7 @@ static bool Unpack(const std::function<bool()>& cancelled, const std::string& pa
// Check for path traversal attacks. // Check for path traversal attacks.
const bool is_path_traversal_attack = const bool is_path_traversal_attack =
(childname.find("\\") != std::string_view::npos) || childname.contains('\\') || childname.contains('/') ||
(childname.find('/') != std::string_view::npos) ||
std::ranges::all_of(childname, [](char c) { return c == '.'; }); std::ranges::all_of(childname, [](char c) { return c == '.'; });
if (is_path_traversal_attack) if (is_path_traversal_attack)
{ {
+3 -4
View File
@@ -33,16 +33,15 @@ u32 GetMemoryTargetSize(std::string_view instr)
constexpr char PAIRED_TAG = 'p'; constexpr char PAIRED_TAG = 'p';
// Actual range is 0 to size - 1; // Actual range is 0 to size - 1;
if (op.find(BYTE_TAG) != std::string::npos) if (op.contains(BYTE_TAG))
{ {
return 1; return 1;
} }
else if (op.find(HALF_TAG) != std::string::npos) else if (op.contains(HALF_TAG))
{ {
return 2; return 2;
} }
else if (op.find(DOUBLE_WORD_TAG) != std::string::npos || else if (op.contains(DOUBLE_WORD_TAG) || op.contains(PAIRED_TAG))
op.find(PAIRED_TAG) != std::string::npos)
{ {
return 8; return 8;
} }
@@ -61,7 +61,7 @@ MemoryCard::MemoryCard(std::string filename, ExpansionInterface::Slot card_slot,
// Fills in the first 5 blocks (MC_HDR_SIZE bytes) // Fills in the first 5 blocks (MC_HDR_SIZE bytes)
const 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 CardFlashId& flash_id = sram.settings_ex.flash_id[Memcard::SLOT_A];
const bool shift_jis = m_filename.find(".JAP.raw") != std::string::npos; const bool shift_jis = m_filename.contains(".JAP.raw");
const u32 rtc_bias = sram.settings.rtc_bias; const u32 rtc_bias = sram.settings.rtc_bias;
const u32 sram_language = static_cast<u32>(sram.settings.language); const u32 sram_language = static_cast<u32>(sram.settings.language);
const u64 format_time = const u64 format_time =
+1 -1
View File
@@ -84,7 +84,7 @@ public:
for (const SaveFile& file : m_files_list) for (const SaveFile& file : m_files_list)
{ {
// files in subdirs are deleted automatically when the subdir is deleted // files in subdirs are deleted automatically when the subdir is deleted
if (file.path.find('/') != std::string::npos) if (file.path.contains('/'))
continue; continue;
const auto result = const auto result =
+1 -1
View File
@@ -106,7 +106,7 @@ static u64 FixupDirectoryEntries(File::FSTEntry* dir, bool is_root)
// Decode escaped invalid file system characters so that games (such as Harry Potter and the // Decode escaped invalid file system characters so that games (such as Harry Potter and the
// Half-Blood Prince) can find what they expect. // Half-Blood Prince) can find what they expect.
if (it->virtualName.find("__") != std::string::npos) if (it->virtualName.contains("__"))
it->virtualName = Common::UnescapeFileName(it->virtualName); it->virtualName = Common::UnescapeFileName(it->virtualName);
// Drop files that have too long filenames. // Drop files that have too long filenames.
+2 -2
View File
@@ -231,10 +231,10 @@ static bool DecompressPacketIntoFolderInternal(sf::Packet& packet, const std::st
std::string name; std::string name;
packet >> name; packet >> name;
if (name.find('/') != std::string::npos) if (name.contains('/'))
return false; return false;
#ifdef _WIN32 #ifdef _WIN32
if (name.find('\\') != std::string::npos) if (name.contains('\\'))
return false; return false;
#endif #endif
if (std::ranges::all_of(name, [](char c) { return c == '.'; })) if (std::ranges::all_of(name, [](char c) { return c == '.'; }))
+10 -10
View File
@@ -96,10 +96,10 @@ void BreakPoints::AddFromStrings(const TBreakPointsStr& bp_strings)
iss.ignore(); iss.ignore();
iss >> std::hex >> bp.address; iss >> std::hex >> bp.address;
iss >> flags; iss >> flags;
bp.is_enabled = flags.find('n') != flags.npos; bp.is_enabled = flags.contains('n');
bp.log_on_hit = flags.find('l') != flags.npos; bp.log_on_hit = flags.contains('l');
bp.break_on_hit = flags.find('b') != flags.npos; bp.break_on_hit = flags.contains('b');
if (flags.find('c') != std::string::npos) if (flags.contains('c'))
{ {
iss >> std::ws; iss >> std::ws;
std::string condition; std::string condition;
@@ -276,12 +276,12 @@ void MemChecks::AddFromStrings(const TMemChecksStr& mc_strings)
iss >> std::hex >> mc.start_address >> mc.end_address >> flags; iss >> std::hex >> mc.start_address >> mc.end_address >> flags;
mc.is_ranged = mc.start_address != mc.end_address; mc.is_ranged = mc.start_address != mc.end_address;
mc.is_enabled = flags.find('n') != flags.npos; mc.is_enabled = flags.contains('n');
mc.is_break_on_read = flags.find('r') != flags.npos; mc.is_break_on_read = flags.contains('r');
mc.is_break_on_write = flags.find('w') != flags.npos; mc.is_break_on_write = flags.contains('w');
mc.log_on_hit = flags.find('l') != flags.npos; mc.log_on_hit = flags.contains('l');
mc.break_on_hit = flags.find('b') != flags.npos; mc.break_on_hit = flags.contains('b');
if (flags.find('c') != std::string::npos) if (flags.contains('c'))
{ {
iss >> std::ws; iss >> std::ws;
std::string condition; std::string condition;
+1 -2
View File
@@ -100,8 +100,7 @@ static double CallstackFunc(expr_func* f, vec_expr_t* args, void* c)
const char* cstr = expr_get_str(&vec_nth(args, 0)); const char* cstr = expr_get_str(&vec_nth(args, 0));
if (cstr != nullptr) if (cstr != nullptr)
{ {
return std::ranges::any_of( return std::ranges::any_of(stack, [cstr](const auto& s) { return s.Name.contains(cstr); });
stack, [cstr](const auto& s) { return s.Name.find(cstr) != std::string::npos; });
} }
return 0; return 0;
+1 -1
View File
@@ -60,7 +60,7 @@ FileDataLoaderHostFS::MakeAbsoluteFromRelative(std::string_view external_relativ
#ifdef _WIN32 #ifdef _WIN32
// Riivolution treats a backslash as just a standard filename character, but we can't replicate // Riivolution treats a backslash as just a standard filename character, but we can't replicate
// this properly on Windows. So if a file contains a backslash, immediately error out. // this properly on Windows. So if a file contains a backslash, immediately error out.
if (external_relative_path.find("\\") != std::string_view::npos) if (external_relative_path.contains("\\"))
return std::nullopt; return std::nullopt;
#endif #endif
+1 -1
View File
@@ -105,7 +105,7 @@ void XRRConfiguration::Update()
unsigned int fullWidth, fullHeight; unsigned int fullWidth, fullHeight;
char* output_name = nullptr; char* output_name = nullptr;
char auxFlag = '\0'; char auxFlag = '\0';
if (fullscreen_display_res.find(':') == std::string::npos) if (!fullscreen_display_res.contains(':'))
{ {
fullWidth = fb_width; fullWidth = fb_width;
fullHeight = fb_height; fullHeight = fb_height;
+4 -4
View File
@@ -245,13 +245,13 @@ void Metal::Util::PopulateBackendInfoFeatures(const VideoConfig& config, Backend
// Initialize DriverDetails first so we can use it later // Initialize DriverDetails first so we can use it later
DriverDetails::Vendor vendor = DriverDetails::VENDOR_UNKNOWN; DriverDetails::Vendor vendor = DriverDetails::VENDOR_UNKNOWN;
std::string name = [[device name] UTF8String]; std::string name = [[device name] UTF8String];
if (name.find("NVIDIA") != std::string::npos) if (name.contains("NVIDIA"))
vendor = DriverDetails::VENDOR_NVIDIA; vendor = DriverDetails::VENDOR_NVIDIA;
else if (name.find("AMD") != std::string::npos) else if (name.contains("AMD"))
vendor = DriverDetails::VENDOR_ATI; vendor = DriverDetails::VENDOR_ATI;
else if (name.find("Intel") != std::string::npos) else if (name.contains("Intel"))
vendor = DriverDetails::VENDOR_INTEL; vendor = DriverDetails::VENDOR_INTEL;
else if (name.find("Apple") != std::string::npos) else if (name.contains("Apple"))
vendor = DriverDetails::VENDOR_APPLE; vendor = DriverDetails::VENDOR_APPLE;
DriverDetails::Init(DriverDetails::API_METAL, vendor, DriverDetails::DRIVER_APPLE, 0.0, DriverDetails::Init(DriverDetails::API_METAL, vendor, DriverDetails::DRIVER_APPLE, 0.0,
DriverDetails::Family::UNKNOWN, std::move(name)); DriverDetails::Family::UNKNOWN, std::move(name));
+5 -6
View File
@@ -50,11 +50,11 @@ void InitDriverInfo()
{ {
vendor = DriverDetails::VENDOR_ATI; vendor = DriverDetails::VENDOR_ATI;
} }
else if (sversion.find("Mesa") != std::string::npos) else if (sversion.contains("Mesa"))
{ {
vendor = DriverDetails::VENDOR_MESA; vendor = DriverDetails::VENDOR_MESA;
} }
else if (svendor.find("Intel") != std::string::npos) else if (svendor.contains("Intel"))
{ {
vendor = DriverDetails::VENDOR_INTEL; vendor = DriverDetails::VENDOR_INTEL;
} }
@@ -118,13 +118,12 @@ void InitDriverInfo()
else if (svendor == "Intel Open Source Technology Center") else if (svendor == "Intel Open Source Technology Center")
{ {
driver = DriverDetails::DRIVER_I965; driver = DriverDetails::DRIVER_I965;
if (srenderer.find("Sandybridge") != std::string::npos) if (srenderer.contains("Sandybridge"))
family = DriverDetails::Family::INTEL_SANDY; family = DriverDetails::Family::INTEL_SANDY;
else if (srenderer.find("Ivybridge") != std::string::npos) else if (srenderer.contains("Ivybridge"))
family = DriverDetails::Family::INTEL_IVY; family = DriverDetails::Family::INTEL_IVY;
} }
else if (srenderer.find("AMD") != std::string::npos || else if (srenderer.contains("AMD") || srenderer.contains("ATI"))
srenderer.find("ATI") != std::string::npos)
{ {
driver = DriverDetails::DRIVER_R600; driver = DriverDetails::DRIVER_R600;
} }
@@ -988,12 +988,11 @@ void VulkanContext::InitDriverDetails()
vendor = DriverDetails::VENDOR_NVIDIA; vendor = DriverDetails::VENDOR_NVIDIA;
driver = DriverDetails::DRIVER_NVIDIA; driver = DriverDetails::DRIVER_NVIDIA;
} }
else if (vendor_id == 0x1002 || vendor_id == 0x1022 || else if (vendor_id == 0x1002 || vendor_id == 0x1022 || device_name.contains("AMD"))
device_name.find("AMD") != std::string::npos)
{ {
// RADV always advertises its name in the device string. // RADV always advertises its name in the device string.
// If not RADV, assume the AMD binary driver. // If not RADV, assume the AMD binary driver.
if (device_name.find("RADV") != std::string::npos) if (device_name.contains("RADV"))
{ {
vendor = DriverDetails::VENDOR_MESA; vendor = DriverDetails::VENDOR_MESA;
driver = DriverDetails::DRIVER_R600; driver = DriverDetails::DRIVER_R600;
@@ -1004,8 +1003,7 @@ void VulkanContext::InitDriverDetails()
driver = DriverDetails::DRIVER_ATI; driver = DriverDetails::DRIVER_ATI;
} }
} }
else if (vendor_id == 0x8086 || vendor_id == 0x8087 || else if (vendor_id == 0x8086 || vendor_id == 0x8087 || device_name.contains("Intel"))
device_name.find("Intel") != std::string::npos)
{ {
// Apart from the driver version, Intel does not appear to provide a way to // Apart from the driver version, Intel does not appear to provide a way to
// differentiate between anv and the binary driver (Skylake+). Assume to be // differentiate between anv and the binary driver (Skylake+). Assume to be
@@ -1018,25 +1016,25 @@ void VulkanContext::InitDriverDetails()
driver = DriverDetails::DRIVER_I965; driver = DriverDetails::DRIVER_I965;
#endif #endif
} }
else if (vendor_id == 0x5143 || device_name.find("Adreno") != std::string::npos) else if (vendor_id == 0x5143 || device_name.contains("Adreno"))
{ {
// Currently only the Qualcomm binary driver exists for Adreno. // Currently only the Qualcomm binary driver exists for Adreno.
vendor = DriverDetails::VENDOR_QUALCOMM; vendor = DriverDetails::VENDOR_QUALCOMM;
driver = DriverDetails::DRIVER_QUALCOMM; driver = DriverDetails::DRIVER_QUALCOMM;
} }
else if (vendor_id == 0x13B6 || device_name.find("Mali") != std::string::npos) else if (vendor_id == 0x13B6 || device_name.contains("Mali"))
{ {
// Currently only the ARM binary driver exists for Mali. // Currently only the ARM binary driver exists for Mali.
vendor = DriverDetails::VENDOR_ARM; vendor = DriverDetails::VENDOR_ARM;
driver = DriverDetails::DRIVER_ARM; driver = DriverDetails::DRIVER_ARM;
} }
else if (vendor_id == 0x1010 || device_name.find("PowerVR") != std::string::npos) else if (vendor_id == 0x1010 || device_name.contains("PowerVR"))
{ {
// Currently only the binary driver exists for PowerVR. // Currently only the binary driver exists for PowerVR.
vendor = DriverDetails::VENDOR_IMGTEC; vendor = DriverDetails::VENDOR_IMGTEC;
driver = DriverDetails::DRIVER_IMGTEC; driver = DriverDetails::DRIVER_IMGTEC;
} }
else if (device_name.find("Apple") != std::string::npos) else if (device_name.contains("Apple"))
{ {
vendor = DriverDetails::VENDOR_APPLE; vendor = DriverDetails::VENDOR_APPLE;
driver = DriverDetails::DRIVER_PORTABILITY; driver = DriverDetails::DRIVER_PORTABILITY;