OSDN Git Service

string_replace(): Fix infinite loop if (replace) contains an occurrence of (find...
authorJochen Tucht <jtuc@users.sourceforge.net>
Sun, 16 May 2010 15:19:15 +0000 (15:19 +0000)
committerJochen Tucht <jtuc@users.sourceforge.net>
Sun, 16 May 2010 15:19:15 +0000 (15:19 +0000)
Src/Common/UnicodeString.cpp

index 3b24f13..df2a52d 100644 (file)
@@ -57,11 +57,12 @@ String string_makelower(const String &str)
  */
 void string_replace(String &target, const String &find, const String &replace)
 {
-       const std::string::size_type replace_len = find.length();
-       std::string::size_type pos = 0;
+       const String::size_type find_len = find.length();
+       const String::size_type replace_len = replace.length();
+       String::size_type pos = 0;
        while ((pos = target.find(find, pos)) != String::npos)
        {
-               target.replace(pos, replace_len, replace);
+               target.replace(pos, find_len, replace);
                pos += replace_len;
        }
 }