From 08a784530e4bbdce4d9051bc579b46aaea2b5c44 Mon Sep 17 00:00:00 2001 From: Jochen Tucht Date: Sun, 16 Sep 2007 07:54:00 +0000 Subject: [PATCH] string_replace(): Fix infinite loop if (find) is prefix of (replace). --- Src/Common/UnicodeString.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Src/Common/UnicodeString.cpp b/Src/Common/UnicodeString.cpp index 728279b81..1f8b286e7 100644 --- a/Src/Common/UnicodeString.cpp +++ b/Src/Common/UnicodeString.cpp @@ -27,13 +27,11 @@ void string_replace(String &target, const String &find, const String &replace) { - const size_t replace_len = find.length(); - std::string::size_type prevPos = 0; - std::string::size_type pos = target.find(find, prevPos); - while (pos != std::string::npos) + const std::string::size_type replace_len = find.length(); + std::string::size_type pos = 0; + while ((pos = target.find(find, pos)) != String::npos) { target.replace(pos, replace_len, replace); - prevPos = pos; - pos = target.find(find, prevPos); + pos += replace_len; } } -- 2.11.0