mirror of
https://github.com/yuzu-emu/yuzu-android
synced 2024-11-24 08:58:19 +00:00
Common: Fix a potential infinite loop in StringUtil's ReplaceAll
This commit is contained in:
parent
335082e74e
commit
2f6ef914db
1 changed files with 8 additions and 3 deletions
|
@ -283,12 +283,17 @@ std::string TabsToSpaces(int tab_size, const std::string &in)
|
||||||
|
|
||||||
std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest)
|
std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest)
|
||||||
{
|
{
|
||||||
while(1)
|
size_t pos = 0;
|
||||||
|
|
||||||
|
if (src == dest)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
while ((pos = result.find(src, pos)) != std::string::npos)
|
||||||
{
|
{
|
||||||
size_t pos = result.find(src);
|
|
||||||
if (pos == std::string::npos) break;
|
|
||||||
result.replace(pos, src.size(), dest);
|
result.replace(pos, src.size(), dest);
|
||||||
|
pos += dest.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue