From 0be43c9cf67aed003006f9c008f079f689436485 Mon Sep 17 00:00:00 2001 From: hashlag Date: Sun, 18 Oct 2026 01:10:34 +0300 Subject: [PATCH] Erase the source SeArray immediately in move assignment operator. --- Chaos/Service/SeArray.hpp | 15 ++++++++++++++- ChaosTests/Service/SeArrayTests.cpp | 9 +++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Chaos/Service/SeArray.hpp b/Chaos/Service/SeArray.hpp index c8bf88e..0119942 100644 --- a/Chaos/Service/SeArray.hpp +++ b/Chaos/Service/SeArray.hpp @@ -27,7 +27,20 @@ public: } SeArray & operator=(const SeArray & other) = default; - SeArray & operator=(SeArray && other) = default; + + SeArray & operator=(SeArray && other) + { + if (this == &other) + { + return *this; + } + + EraseImpl(); + Storage_ = std::move(other.Storage_); + other.EraseImpl(); + + return *this; + } ~SeArray() { diff --git a/ChaosTests/Service/SeArrayTests.cpp b/ChaosTests/Service/SeArrayTests.cpp index 3d6e33f..199ad64 100644 --- a/ChaosTests/Service/SeArrayTests.cpp +++ b/ChaosTests/Service/SeArrayTests.cpp @@ -305,6 +305,9 @@ TEST(SeArrayTests, MoveAssignTest) ASSERT_EQ(0xaa, arr1[0]); ASSERT_EQ(0xbb, arr1[1]); + + ASSERT_EQ(0, arr2[0]); + ASSERT_EQ(0, arr2[1]); } { @@ -324,6 +327,12 @@ TEST(SeArrayTests, MoveAssignTest) ASSERT_EQ(0, arr1[2]); ASSERT_EQ(0, arr1[3]); ASSERT_EQ(0, arr1[4]); + + ASSERT_EQ(0, arr2[0]); + ASSERT_EQ(0, arr2[1]); + ASSERT_EQ(0, arr2[2]); + ASSERT_EQ(0, arr2[3]); + ASSERT_EQ(0, arr2[4]); } }