diff --git a/Redirector/Utils.cpp b/Redirector/Utils.cpp index 17c82396..f340732c 100644 --- a/Redirector/Utils.cpp +++ b/Redirector/Utils.cpp @@ -2,10 +2,10 @@ string ws2s(const wstring str) { - auto length = WideCharToMultiByte(CP_ACP, 0, str.c_str(), (int)str.length(), NULL, 0, NULL, NULL); - auto buffer = new char[length](); + auto length = WideCharToMultiByte(CP_ACP, 0, str.c_str(), static_cast(str.length()), NULL, 0, NULL, NULL); + auto buffer = new char[length + 1](); - WideCharToMultiByte(CP_ACP, 0, str.c_str(), (int)str.length(), buffer, length, NULL, NULL); + WideCharToMultiByte(CP_ACP, 0, str.c_str(), static_cast(str.length()), buffer, length, NULL, NULL); auto data = string(buffer); delete[] buffer; @@ -15,10 +15,10 @@ string ws2s(const wstring str) wstring s2ws(const string str) { - auto length = MultiByteToWideChar(CP_ACP, 0, str.c_str(), (int)str.length(), NULL, 0); - auto buffer = new wchar_t[length](); + auto length = MultiByteToWideChar(CP_ACP, 0, str.c_str(), static_cast(str.length()), NULL, 0); + auto buffer = new wchar_t[length + 1](); - MultiByteToWideChar(CP_ACP, 0, str.c_str(), (int)str.length(), buffer, length); + MultiByteToWideChar(CP_ACP, 0, str.c_str(), static_cast(str.length()), buffer, length); auto data = wstring(buffer); delete[] buffer;