Merge pull request #2593 from JuhaSointusalo/lib-fix-wide-char-conv

lib: fix wide char conversion functions
This commit is contained in:
David Anderson 2018-07-10 14:13:58 -07:00 committed by GitHub
commit 137b6563b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -125,7 +125,7 @@ std::wstring boinc_ascii_to_wide(const std::string& str) {
int length_wide = MultiByteToWideChar(CP_ACP, 0, str.data(), -1, NULL, 0);
wchar_t *string_wide = static_cast<wchar_t*>(_alloca((length_wide * sizeof(wchar_t)) + sizeof(wchar_t)));
MultiByteToWideChar(CP_ACP, 0, str.data(), -1, string_wide, length_wide);
std::wstring result(string_wide, length_wide);
std::wstring result(string_wide, length_wide - 1);
return result;
}
@ -133,7 +133,7 @@ std::string boinc_wide_to_ascii(const std::wstring& str) {
int length_ansi = WideCharToMultiByte(CP_UTF8, 0, str.data(), -1, NULL, 0, NULL, NULL);
char* string_ansi = static_cast<char*>(_alloca(length_ansi + sizeof(char)));
WideCharToMultiByte(CP_UTF8, 0, str.data(), -1, string_ansi, length_ansi, NULL, NULL);
std::string result(string_ansi, length_ansi);
std::string result(string_ansi, length_ansi - 1);
return result;
}