diff options
author | Lioncash <mathew1800@gmail.com> | 2014-09-08 14:48:59 -0400 |
---|---|---|
committer | Lioncash <mathew1800@gmail.com> | 2014-09-08 14:48:59 -0400 |
commit | 2f6ef914dbeb660b50074cadadd52c1f11829637 (patch) | |
tree | 1be82ffd9de901b1adcde3d3484dcf7fd34e00e4 /src/common/string_util.cpp | |
parent | 335082e74e5f015450f1ad57cb90d1f8fd4afbdb (diff) |
Common: Fix a potential infinite loop in StringUtil's ReplaceAll
Diffstat (limited to 'src/common/string_util.cpp')
-rw-r--r-- | src/common/string_util.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index c1f22bda39..e78aed75d9 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -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; } |