From 2e211f16b777f7418d39e87944eb8b209ed68c33 Mon Sep 17 00:00:00 2001 From: Dan Jump Date: Fri, 30 Oct 2026 08:28:08 -0700 Subject: [PATCH 1/2] Avoid clearing com_array object representation Reset the detached array's data and size members explicitly so detach_abi does not write through the representation of a non-trivially-copyable object. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8b45cfea-cc0f-4a1f-8b2a-86c89d063c6c Hostname: DanJump0 --- strings/base_array.h | 3 ++- test/old_tests/UnitTests/array.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/strings/base_array.h b/strings/base_array.h index d29bee883..369f6cf2c 100644 --- a/strings/base_array.h +++ b/strings/base_array.h @@ -382,7 +382,8 @@ WINRT_EXPORT namespace winrt std::memset(&result, 0, sizeof(result)); result.first = this->size(); result.second = *reinterpret_cast*>(this); - std::memset(this, 0, sizeof(com_array)); + this->m_data = nullptr; + this->m_size = 0; #else std::pair> result(this->size(), *reinterpret_cast*>(this)); this->m_data = nullptr; diff --git a/test/old_tests/UnitTests/array.cpp b/test/old_tests/UnitTests/array.cpp index 2b5952004..d494d951c 100644 --- a/test/old_tests/UnitTests/array.cpp +++ b/test/old_tests/UnitTests/array.cpp @@ -1079,6 +1079,19 @@ TEST_CASE("com_array,move") REQUIRE(b.empty()); } +TEST_CASE("com_array,detach") +{ + com_array a{ 1, 2, 3 }; + auto detached = detach_abi(a); + com_array b(detached.second, detached.first, take_ownership_from_abi); + + REQUIRE(a.empty()); + REQUIRE(3 == b.size()); + REQUIRE(b[0] == 1); + REQUIRE(b[1] == 2); + REQUIRE(b[2] == 3); +} + // // Now some tests covering producing and consuming arrays // From 7a78cfc3db21d07f48849e912c38b4f6f6c2dc08 Mon Sep 17 00:00:00 2001 From: Dan Jump Date: Fri, 30 Oct 2026 08:29:06 -0700 Subject: [PATCH 2/2] Share detached array state reset Reset the com_array members after the compiler-specific result construction so both paths use the same ownership-release logic. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8b45cfea-cc0f-4a1f-8b2a-86c89d063c6c Hostname: DanJump0 --- strings/base_array.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/strings/base_array.h b/strings/base_array.h index 369f6cf2c..73914e624 100644 --- a/strings/base_array.h +++ b/strings/base_array.h @@ -382,13 +382,11 @@ WINRT_EXPORT namespace winrt std::memset(&result, 0, sizeof(result)); result.first = this->size(); result.second = *reinterpret_cast*>(this); - this->m_data = nullptr; - this->m_size = 0; #else std::pair> result(this->size(), *reinterpret_cast*>(this)); +#endif this->m_data = nullptr; this->m_size = 0; -#endif return result; }