Skip to content
This repository
Browse code

[fix] string copy allocated in function params can be destroyed befor…

…e access via *end pointer causing EXC_BAD_ACCESS
  • Loading branch information...
commit 37f3554a06dfd456f2308a3403585a1265b79183 1 parent 8193a53
night199uk authored July 20, 2013

Showing 1 changed file with 12 additions and 6 deletions. Show diff stats Hide diff stats

  1. 18  xbmc/utils/Variant.cpp
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 37f3554

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