File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -92,7 +92,7 @@ const char * tUtil::bstr2string(BSTR bstr)
92
92
if (!size)
93
93
LUACOM_ERROR (tUtil::GetErrorMessage (GetLastError ()));
94
94
95
- str = new char [size];
95
+ str = new char [size + 1 ];
96
96
97
97
result = WideCharToMultiByte (
98
98
CP_UTF8, // code page
@@ -108,6 +108,7 @@ const char * tUtil::bstr2string(BSTR bstr)
108
108
if (!result)
109
109
LUACOM_ERROR (tUtil::GetErrorMessage (GetLastError ()));
110
110
111
+ str [size] = ' \0 ' ;
111
112
}
112
113
else
113
114
{
@@ -165,7 +166,7 @@ const char * tUtil::bstr2string(BSTR bstr, size_t& computedSize)
165
166
if (!size)
166
167
LUACOM_ERROR (tUtil::GetErrorMessage (GetLastError ()));
167
168
168
- str = new char [size];
169
+ str = new char [size + 1 ];
169
170
170
171
result = WideCharToMultiByte (
171
172
CP_UTF8, // code page
@@ -180,7 +181,9 @@ const char * tUtil::bstr2string(BSTR bstr, size_t& computedSize)
180
181
181
182
if (!result)
182
183
LUACOM_ERROR (tUtil::GetErrorMessage (GetLastError ()));
183
-
184
+
185
+ str [size] = ' \0 ' ;
186
+
184
187
computedSize = size; // Now holds the actual length of the string
185
188
}
186
189
else
@@ -200,7 +203,7 @@ const char * tUtil::bstr2string(BSTR bstr, size_t& computedSize)
200
203
str[0 ] = ' \0 ' ;
201
204
}
202
205
203
- tUtil::string_buffer.copyToBuffer (str, computedSize);
206
+ tUtil::string_buffer.copyToBuffer (str, computedSize + 1 );
204
207
205
208
delete[] str;
206
209
You can’t perform that action at this time.
0 commit comments