Skip to content

Commit

Permalink
StdStringEncodingConverter: Fix exception on empty inputs by returnin…
Browse files Browse the repository at this point in the history
…g early
  • Loading branch information
Fulgen301 committed Dec 3, 2024
1 parent 23064b1 commit 33f2b57
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/StdStringEncodingConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@

std::wstring StdStringEncodingConverter::WinAcpToUtf16(const std::string_view multiByte)
{
if (multiByte.empty())
{
return L"";
}

std::wstring result;
result.resize_and_overwrite(MultiByteToWideChar(CP_ACP, multiByte, {}), [&multiByte](wchar_t *const ptr, const std::size_t size)
{
Expand All @@ -32,6 +37,11 @@ std::wstring StdStringEncodingConverter::WinAcpToUtf16(const std::string_view mu

std::string StdStringEncodingConverter::Utf16ToWinAcp(const std::wstring_view wide)
{
if (wide.empty())
{
return "";
}

std::string result;
result.resize_and_overwrite(WideCharToMultiByte(CP_ACP, wide, {}), [&wide](char *const ptr, const std::size_t size)
{
Expand Down

0 comments on commit 33f2b57

Please sign in to comment.