Fix endless loop in ReplaceString (#9077)

This commit is contained in:
Vovodroid 2025-03-26 05:33:52 +02:00 committed by GitHub
parent 108eeaed0a
commit 00811ee5bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -39,7 +39,10 @@ std::set<std::string> SplitStringAndRemoveDuplicateElement(const std::string &st
void ReplaceString(std::string &resource_str, const std::string &old_str, const std::string &new_str)
{
std::string::size_type pos = 0;
while ((pos = resource_str.find(old_str)) != std::string::npos) { resource_str.replace(pos, old_str.length(), new_str); }
while ((pos = resource_str.find(old_str, pos)) != std::string::npos) {
resource_str.replace(pos, old_str.length(), new_str);
pos += new_str.length(); //advance position to continue after replacement
}
}
}