Skip to content

Commit

Permalink
Fix concat_hstring for 0-length string (#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnewthing authored Jun 30, 2020
1 parent fba255d commit aeb78bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion strings/base_string_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ namespace winrt::impl
{
inline hstring concat_hstring(std::wstring_view const& left, std::wstring_view const& right)
{
hstring_builder text(static_cast<uint32_t>(left.size() + right.size()));
auto size = static_cast<uint32_t>(left.size() + right.size());
if (size == 0)
{
return{};
}
hstring_builder text(size);
memcpy_s(text.data(), left.size() * sizeof(wchar_t), left.data(), left.size() * sizeof(wchar_t));
memcpy_s(text.data() + left.size(), right.size() * sizeof(wchar_t), right.data(), right.size() * sizeof(wchar_t));
return text.to_hstring();
Expand Down
3 changes: 3 additions & 0 deletions test/old_tests/UnitTests/hstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,7 @@ TEST_CASE("hstring, concat")
REQUIRE(hstring() + s == L"abc");
REQUIRE(s + L"" == L"abc");
REQUIRE(L"" + s == L"abc");

REQUIRE(hstring() + hstring() == L"");
REQUIRE(get_abi(hstring() + hstring()) == nullptr);
}

0 comments on commit aeb78bb

Please sign in to comment.