Skip to content
This repository
Browse code

Merge pull request #2991 from night199uk/misc

[fixes] Fix a couple of EXC_BAD_ACCESS memory access bugs on OSX that cause real instability
  • Loading branch information...
commit c18fcf270bdad36ee8ee6633d8fecd40aaa693c6 2 parents ecf024b + 2a3ad14
night199uk authored July 22, 2013
6  xbmc/guilib/Texture.cpp
@@ -87,7 +87,11 @@ void CBaseTexture::Allocate(unsigned int width, unsigned int height, unsigned in
87 87
     // we crash in CPicture::ScaleImage in ffmpegs swscale
88 88
     // because it tries to access beyond the source memory
89 89
     // (happens on osx and ios)
90  
-    m_textureWidth = ((m_textureWidth + 1) / 2) * 2;
  90
+    // UPDATE: don't just update to be on an even width;
  91
+    // ffmpegs swscale relies on a 16-byte stride on some systems
  92
+    // so the textureWidth needs to be a multiple of 16. see ffmpeg
  93
+    // swscale headers for more info.
  94
+    m_textureWidth = ((m_textureWidth + 15) / 16) * 16;
91 95
   }
92 96
 
93 97
   // check for max texture size
18  xbmc/utils/Variant.cpp
@@ -65,7 +65,8 @@ wstring trimRight(const wstring &str)
65 65
 int64_t str2int64(const string &str, int64_t fallback /* = 0 */)
66 66
 {
67 67
   char *end = NULL;
68  
-  int64_t result = strtoll(trimRight(str).c_str(), &end, 0);
  68
+  string tmp = trimRight(str);
  69
+  int64_t result = strtoll(tmp.c_str(), &end, 0);
69 70
   if (end == NULL || *end == '\0')
70 71
     return result;
71 72
 
@@ -75,7 +76,8 @@ int64_t str2int64(const string &str, int64_t fallback /* = 0 */)
75 76
 int64_t str2int64(const wstring &str, int64_t fallback /* = 0 */)
76 77
 {
77 78
   wchar_t *end = NULL;
78  
-  int64_t result = wcstoll(trimRight(str).c_str(), &end, 0);
  79
+  wstring tmp = trimRight(str);
  80
+  int64_t result = wcstoll(tmp.c_str(), &end, 0);
79 81
   if (end == NULL || *end == '\0')
80 82
     return result;
81 83
 
@@ -85,7 +87,8 @@ int64_t str2int64(const wstring &str, int64_t fallback /* = 0 */)
85 87
 uint64_t str2uint64(const string &str, uint64_t fallback /* = 0 */)
86 88
 {
87 89
   char *end = NULL;
88  
-  uint64_t result = strtoull(trimRight(str).c_str(), &end, 0);
  90
+  string tmp = trimRight(str);
  91
+  uint64_t result = strtoull(tmp.c_str(), &end, 0);
89 92
   if (end == NULL || *end == '\0')
90 93
     return result;
91 94
 
@@ -95,7 +98,8 @@ uint64_t str2uint64(const string &str, uint64_t fallback /* = 0 */)
95 98
 uint64_t str2uint64(const wstring &str, uint64_t fallback /* = 0 */)
96 99
 {
97 100
   wchar_t *end = NULL;
98  
-  uint64_t result = wcstoull(trimRight(str).c_str(), &end, 0);
  101
+  wstring tmp = trimRight(str);
  102
+  uint64_t result = wcstoull(tmp.c_str(), &end, 0);
99 103
   if (end == NULL || *end == '\0')
100 104
     return result;
101 105
 
@@ -105,7 +109,8 @@ uint64_t str2uint64(const wstring &str, uint64_t fallback /* = 0 */)
105 109
 double str2double(const string &str, double fallback /* = 0.0 */)
106 110
 {
107 111
   char *end = NULL;
108  
-  double result = strtod(trimRight(str).c_str(), &end);
  112
+  string tmp = trimRight(str);
  113
+  double result = strtod(tmp.c_str(), &end);
109 114
   if (end == NULL || *end == '\0')
110 115
     return result;
111 116
 
@@ -115,7 +120,8 @@ double str2double(const string &str, double fallback /* = 0.0 */)
115 120
 double str2double(const wstring &str, double fallback /* = 0.0 */)
116 121
 {
117 122
   wchar_t *end = NULL;
118  
-  double result = wcstod(trimRight(str).c_str(), &end);
  123
+  wstring tmp = trimRight(str);
  124
+  double result = wcstod(tmp.c_str(), &end);
119 125
   if (end == NULL || *end == '\0')
120 126
     return result;
121 127
 

0 notes on commit c18fcf2

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