summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2014-09-10 02:53:33 +0200
committerbunnei <bunneidev@gmail.com>2014-09-10 02:53:33 +0200
commit8891c274255e478ecf40c9b6792dede1745ca9f8 (patch)
treea262c4f67eeb3e2e5a0f2d05070035b4fa30da6c
parentMerge pull request #102 from lioncash/define (diff)
parentCommon: Fix a potential infinite loop in StringUtil's ReplaceAll (diff)
downloadyuzu-8891c274255e478ecf40c9b6792dede1745ca9f8.tar
yuzu-8891c274255e478ecf40c9b6792dede1745ca9f8.tar.gz
yuzu-8891c274255e478ecf40c9b6792dede1745ca9f8.tar.bz2
yuzu-8891c274255e478ecf40c9b6792dede1745ca9f8.tar.lz
yuzu-8891c274255e478ecf40c9b6792dede1745ca9f8.tar.xz
yuzu-8891c274255e478ecf40c9b6792dede1745ca9f8.tar.zst
yuzu-8891c274255e478ecf40c9b6792dede1745ca9f8.zip
-rw-r--r--src/common/string_util.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp
index c1f22bda3..e78aed75d 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;
}