Skip to content
This repository
Browse code

[Fix][StringUtils] Prevent infinite loop or crash.

Example:

  std::string rep = "1";
  StringUtils::Replace(rep,"",""); //infinite loop
  StringUtils::Replace(rep,"","1"); //crash std::bad_alloc
  • Loading branch information...
commit 4c702cb0097a4a8932c0cf4486ea40f75335369e 1 parent 402e7f5
Andreas Zelend authored September 13, 2013

Showing 1 changed file with 3 additions and 0 deletions. Show diff stats Hide diff stats

  1. 3  xbmc/utils/StringUtils.cpp
3  xbmc/utils/StringUtils.cpp
@@ -209,6 +209,9 @@ int StringUtils::Replace(string &str, char oldChar, char newChar)
209 209
 
210 210
 int StringUtils::Replace(std::string &str, const std::string &oldStr, const std::string &newStr)
211 211
 {
  212
+  if (oldStr.empty())
  213
+    return 0;
  214
+
212 215
   int replacedChars = 0;
213 216
   size_t index = 0;
214 217
   

0 notes on commit 4c702cb

Please sign in to comment.
Something went wrong with that request. Please try again.