Guest User

Untitled

a guest
Dec 12th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.39 KB | None | 0 0
  1. diff --git a/xbmc/utils/StringUtils.cpp b/xbmc/utils/StringUtils.cpp
  2. index d727c3d..8b6c066 100644
  3. --- a/xbmc/utils/StringUtils.cpp
  4. +++ b/xbmc/utils/StringUtils.cpp
  5. @@ -48,7 +48,7 @@ const char* ADDON_GUID_RE = "^(\\{){0,1}[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-
  6.  const CStdString StringUtils::EmptyString = "";
  7.  CStdString StringUtils::m_lastUUID = "";
  8.  
  9. -string StringUtils::Format(const string &fmt, ...)
  10. +string StringUtils::Format(const char *fmt, ...)
  11.  {
  12.    va_list args;
  13.    va_start(args, fmt);
  14. @@ -58,29 +58,44 @@ string StringUtils::Format(const string &fmt, ...)
  15.    return str;
  16.  }
  17.  
  18. -string StringUtils::FormatV(const string &fmt, va_list args)
  19. +string StringUtils::FormatV(const char *fmt, va_list args)
  20.  {
  21.    int size = FORMAT_BLOCK_SIZE;
  22. -  string str;
  23.    va_list argCopy;
  24.  
  25. +  char *cstr = reinterpret_cast<char*>(malloc(sizeof(char) * size));
  26. +  if (cstr == NULL)
  27. +    return "";
  28. +
  29.    while (1)
  30.    {
  31. -    str.resize(size);
  32.      va_copy(argCopy, args);
  33.  
  34. -    int nActual = vsnprintf((char *)str.c_str(), size, fmt.c_str(), argCopy);
  35. +    int nActual = vsnprintf(cstr, size, fmt, argCopy);
  36.      va_end(argCopy);
  37.  
  38.      if (nActual > -1 && nActual < size) // We got a valid result
  39. +    {
  40. +      string str(cstr, nActual);
  41. +      free(cstr);
  42.        return str;
  43. +    }
  44.      if (nActual > -1)                   // Exactly what we will need (glibc 2.1)
  45.        size = nActual + 1;
  46.      else                                // Let's try to double the size (glibc 2.0)
  47.        size *= 2;
  48. +
  49. +    char *new_cstr = reinterpret_cast<char*>(realloc(cstr, sizeof(char) * size));
  50. +    if (new_cstr == NULL)
  51. +    {
  52. +      free(cstr);
  53. +      return "";
  54. +    }
  55. +
  56. +    cstr = new_cstr;
  57.    }
  58.  
  59. -  return str;
  60. +  return "";
  61.  }
  62.  
  63.  void StringUtils::ToUpper(string &str)
  64. diff --git a/xbmc/utils/StringUtils.h b/xbmc/utils/StringUtils.h
  65. index 95d2866..4179d2b 100644
  66. --- a/xbmc/utils/StringUtils.h
  67. +++ b/xbmc/utils/StringUtils.h
  68. @@ -39,8 +39,8 @@
  69.  class StringUtils
  70.  {
  71.  public:
  72. -  static std::string Format(const std::string &fmt, ...);
  73. -  static std::string FormatV(const std::string &fmt, va_list args);
  74. +  static std::string Format(const char *fmt, ...);
  75. +  static std::string FormatV(const char *fmt, va_list args);
  76.    static void ToUpper(std::string &str);
  77.    static void ToLower(std::string &str);
  78.    static bool EqualsNoCase(const std::string &str1, const std::string &str2);
Add Comment
Please, Sign In to add comment