Commit 1ddcca86 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

PlatformHelpers: Avoid allocating unchecked data on the stack

parent 7bd36e45
...@@ -38,9 +38,9 @@ ToPlatformString(const char *str) { ...@@ -38,9 +38,9 @@ ToPlatformString(const char *str) {
size_t len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); size_t len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
if (len == 0) if (len == 0)
return nullptr; return nullptr;
wchar_t* w_str = reinterpret_cast<wchar_t*>(alloca(len * sizeof(*w_str))); std::unique_ptr<wchar_t[]> w_str(new wchar_t[len]);
MultiByteToWideChar(CP_UTF8, 0, str, -1, w_str, len); MultiByteToWideChar(CP_UTF8, 0, str, -1, w_str.get(), len);
return ref new Platform::String(w_str); return ref new Platform::String(w_str.get());
} }
Platform::String^ Platform::String^
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment