aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/private/SkTArray.h6
-rw-r--r--tests/TArrayTest.cpp15
2 files changed, 21 insertions, 0 deletions
diff --git a/include/private/SkTArray.h b/include/private/SkTArray.h
index fdf96c87bc..4b700d2d29 100644
--- a/include/private/SkTArray.h
+++ b/include/private/SkTArray.h
@@ -59,6 +59,9 @@ public:
}
SkTArray& operator=(const SkTArray& that) {
+ if (this == &that) {
+ return *this;
+ }
for (int i = 0; i < fCount; ++i) {
fItemArray[i].~T();
}
@@ -69,6 +72,9 @@ public:
return *this;
}
SkTArray& operator=(SkTArray&& that) {
+ if (this == &that) {
+ return *this;
+ }
for (int i = 0; i < fCount; ++i) {
fItemArray[i].~T();
}
diff --git a/tests/TArrayTest.cpp b/tests/TArrayTest.cpp
index 6e23c49b35..0e18e9f96d 100644
--- a/tests/TArrayTest.cpp
+++ b/tests/TArrayTest.cpp
@@ -281,6 +281,19 @@ void test_unnecessary_alloc(skiatest::Reporter* reporter) {
}
}
+static void test_self_assignment(skiatest::Reporter* reporter) {
+ SkTArray<int> a;
+ a.push_back(1);
+ REPORTER_ASSERT(reporter, !a.empty());
+ REPORTER_ASSERT(reporter, a.count() == 1);
+ REPORTER_ASSERT(reporter, a[0] == 1);
+
+ a = a;
+ REPORTER_ASSERT(reporter, !a.empty());
+ REPORTER_ASSERT(reporter, a.count() == 1);
+ REPORTER_ASSERT(reporter, a[0] == 1);
+}
+
DEF_TEST(TArray, reporter) {
TestTSet_basic<true>(reporter);
TestTSet_basic<false>(reporter);
@@ -296,4 +309,6 @@ DEF_TEST(TArray, reporter) {
test_move(reporter);
test_unnecessary_alloc(reporter);
+
+ test_self_assignment(reporter);
}