Skip to content
Snippets Groups Projects
Commit 2f6ef914 authored by Lioncash's avatar Lioncash
Browse files

Common: Fix a potential infinite loop in StringUtil's ReplaceAll

parent 335082e7
No related branches found
No related tags found
No related merge requests found
......@@ -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)
{
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);
pos += dest.length();
}
return result;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment