Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common: Fix a potential infinite loop in ReplaceAll #983

Merged
merged 1 commit into from Sep 6, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions Source/Core/Common/StringUtil.cpp
Expand Up @@ -281,12 +281,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;
}

Expand Down