You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by qi...@apache.org on 2021/07/27 12:45:30 UTC
[mesos] branch master updated: LinkedHashMap: fixed handling of
self-assignment.
This is an automated email from the ASF dual-hosted git repository.
qianzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
The following commit(s) were added to refs/heads/master by this push:
new f343811 LinkedHashMap: fixed handling of self-assignment.
f343811 is described below
commit f34381173dbb90a14ebdea58bc52ee8bd2bba64f
Author: Charles-Francois Natali <cf...@gmail.com>
AuthorDate: Tue Jul 27 20:39:21 2021 +0800
LinkedHashMap: fixed handling of self-assignment.
Self-assigning a LinkedHashMap i.e. `map = map` would cause the map
to be cleared.
Found with clang-tidy.
This closes #400
---
3rdparty/stout/include/stout/linkedhashmap.hpp | 12 +++++++-----
3rdparty/stout/tests/linkedhashmap_tests.cpp | 7 +++++++
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/3rdparty/stout/include/stout/linkedhashmap.hpp b/3rdparty/stout/include/stout/linkedhashmap.hpp
index 6bf71ad..a4d86c6 100644
--- a/3rdparty/stout/include/stout/linkedhashmap.hpp
+++ b/3rdparty/stout/include/stout/linkedhashmap.hpp
@@ -46,13 +46,15 @@ public:
LinkedHashMap& operator=(const LinkedHashMap<Key, Value>& other)
{
- clear();
+ if (this != &other) {
+ clear();
- entries_ = other.entries_;
+ entries_ = other.entries_;
- // Build up the index.
- for (auto it = entries_.begin(); it != entries_.end(); ++it) {
- keys_[it->first] = it;
+ // Build up the index.
+ for (auto it = entries_.begin(); it != entries_.end(); ++it) {
+ keys_[it->first] = it;
+ }
}
return *this;
diff --git a/3rdparty/stout/tests/linkedhashmap_tests.cpp b/3rdparty/stout/tests/linkedhashmap_tests.cpp
index a48d97a..e9179de 100644
--- a/3rdparty/stout/tests/linkedhashmap_tests.cpp
+++ b/3rdparty/stout/tests/linkedhashmap_tests.cpp
@@ -236,4 +236,11 @@ TEST(LinkedHashMapTest, Assignment)
EXPECT_NE(map.keys(), copy.keys());
EXPECT_NE(map.values(), copy.values());
+
+ // Test self-assignment.
+ copy = map;
+ map = map;
+
+ EXPECT_EQ(copy.keys(), map.keys());
+ EXPECT_EQ(copy.values(), map.values());
}