From 8c75c6e62e5e11b54e5585c7a4d1329f9212b1d4 Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer Date: Sat, 22 Aug 2009 00:04:28 +0200 Subject: [PATCH] Fix possible endless loop in replace_all Inside replace all, start the search for the next appearance from the end position of the replacement, not from the end of the occurrence. Otherwise, replace_all (&str, "\"", "\\\"") will result in an endless loop. --- flower/std-string.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flower/std-string.cc b/flower/std-string.cc index 285c51883c..53fd548bfa 100644 --- a/flower/std-string.cc +++ b/flower/std-string.cc @@ -80,7 +80,8 @@ string & replace_all (string *str, string const &find, string const &replace) { ssize len = find.length (); - for (ssize i = str->find (find); i != NPOS; i = str->find (find, i + len)) + ssize replen = replace.length (); + for (ssize i = str->find (find); i != NPOS; i = str->find (find, i + replen)) *str = str->replace (i, len, replace); return *str; } -- 2.39.5