diff options
| author | shuffle2 <godisgovernment@gmail.com> | 2014-09-06 12:00:23 -0700 |
|---|---|---|
| committer | shuffle2 <godisgovernment@gmail.com> | 2014-09-06 12:00:23 -0700 |
| commit | 85fd8c2bec5cf753c51f81d44c681b7de558d91e (patch) | |
| tree | 6640b0a92f1873d217cfca0a7b53f7e310ca10f5 /Source/Core/Common/StringUtil.cpp | |
| parent | 227b79bf84905eb4a0114b3a87c706afcbf5c7a8 (diff) | |
| parent | 3e0c04a83e99847e5e846ce8c198bb8a5d26343f (diff) | |
Merge pull request #983 from lioncash/lol-str
Common: Fix a potential infinite loop in ReplaceAll
Diffstat (limited to 'Source/Core/Common/StringUtil.cpp')
| -rw-r--r-- | Source/Core/Common/StringUtil.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index 3239628b62..91d451a03f 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -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; } |
