]> git.donarmstrong.com Git - lilypond.git/commitdiff
Fix possible endless loop in replace_all
authorReinhold Kainhofer <reinhold@kainhofer.com>
Fri, 21 Aug 2009 22:04:28 +0000 (00:04 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Fri, 21 Aug 2009 22:10:37 +0000 (00:10 +0200)
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

index 285c51883c5d1fc0a7727816a3e99ab0e5da2e03..53fd548bfa340f422fc6cce872f6ed590ceb967f 100644 (file)
@@ -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;
 }