From 0cfa60b657473b053332b8e24b0ea8c0aabe8dc7 Mon Sep 17 00:00:00 2001 From: "lane.wei" Date: Thu, 18 Jul 2024 17:05:40 +0800 Subject: [PATCH] FIX: config: fix a endless loop issue when replace string jira: STUDIO-7545 Change-Id: I7ea06556142242f44b183599d9d23d063ad509f9 (cherry picked from commit 842e238d6265abb34f33614c255d1292c3345c34) --- src/libslic3r/PrintConfig.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 4714c582f..20ccc770d 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -38,7 +38,12 @@ std::set SplitStringAndRemoveDuplicateElement(const std::string &st void ReplaceString(std::string &resource_str, const std::string &old_str, const std::string &new_str) { std::string::size_type pos = 0; - while ((pos = resource_str.find(old_str)) != std::string::npos) { resource_str.replace(pos, old_str.length(), new_str); } + size_t new_size = 0; + while ((pos = resource_str.find(old_str, pos + new_size)) != std::string::npos) + { + resource_str.replace(pos, old_str.length(), new_str); + new_size = new_str.size(); + } } }