lib/icu: add null terminate in win32 string and wstring
This commit is contained in:
parent
9f5c6d29b2
commit
169810e8f4
@ -34,9 +34,10 @@ WideCharToMultiByte(unsigned code_page, std::wstring_view src)
|
|||||||
if (length <= 0)
|
if (length <= 0)
|
||||||
throw MakeLastError("Failed to convert from Unicode");
|
throw MakeLastError("Failed to convert from Unicode");
|
||||||
|
|
||||||
std::unique_ptr<char[]> buffer(new char[length]);
|
auto buffer = std::make_unique<char[]>(length + 1);
|
||||||
|
buffer[length] = '\0';
|
||||||
length = WideCharToMultiByte(code_page, 0, src.data(), src.size(),
|
length = WideCharToMultiByte(code_page, 0, src.data(), src.size(),
|
||||||
buffer.get(), length,
|
buffer.get(), length + 1,
|
||||||
nullptr, nullptr);
|
nullptr, nullptr);
|
||||||
if (length <= 0)
|
if (length <= 0)
|
||||||
throw MakeLastError("Failed to convert from Unicode");
|
throw MakeLastError("Failed to convert from Unicode");
|
||||||
@ -52,9 +53,10 @@ MultiByteToWideChar(unsigned code_page, std::string_view src)
|
|||||||
if (length <= 0)
|
if (length <= 0)
|
||||||
throw MakeLastError("Failed to convert to Unicode");
|
throw MakeLastError("Failed to convert to Unicode");
|
||||||
|
|
||||||
std::unique_ptr<wchar_t[]> buffer(new wchar_t[length]);
|
auto buffer = std::make_unique<wchar_t[]>(length + 1);
|
||||||
|
buffer[length] = L'\0';
|
||||||
length = MultiByteToWideChar(code_page, 0, src.data(), src.size(),
|
length = MultiByteToWideChar(code_page, 0, src.data(), src.size(),
|
||||||
buffer.get(), length);
|
buffer.get(), length + 1);
|
||||||
if (length <= 0)
|
if (length <= 0)
|
||||||
throw MakeLastError("Failed to convert to Unicode");
|
throw MakeLastError("Failed to convert to Unicode");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user