Skip to content

Commit 32b1d13

Browse files
committed
refactor: add self-assign checks to classes which violate the clang-tidy check
Both of these cases appear to be harmless, but adding the tests allows us to turn on the aggressive clang-tidy checks.
1 parent 0b94fb8 commit 32b1d13

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/arith_uint256.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ class base_uint
4343

4444
base_uint& operator=(const base_uint& b)
4545
{
46-
for (int i = 0; i < WIDTH; i++)
47-
pn[i] = b.pn[i];
46+
if (this != &b) {
47+
for (int i = 0; i < WIDTH; i++)
48+
pn[i] = b.pn[i];
49+
}
4850
return *this;
4951
}
5052

src/key.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ class CKey
7575

7676
CKey& operator=(const CKey& other)
7777
{
78-
if (other.keydata) {
79-
MakeKeyData();
80-
*keydata = *other.keydata;
81-
} else {
82-
ClearKeyData();
78+
if (this != &other) {
79+
if (other.keydata) {
80+
MakeKeyData();
81+
*keydata = *other.keydata;
82+
} else {
83+
ClearKeyData();
84+
}
85+
fCompressed = other.fCompressed;
8386
}
84-
fCompressed = other.fCompressed;
8587
return *this;
8688
}
8789

src/test/util_tests.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,8 +1508,10 @@ struct Tracker
15081508
Tracker(Tracker&& t) noexcept : origin(t.origin), copies(t.copies) {}
15091509
Tracker& operator=(const Tracker& t) noexcept
15101510
{
1511-
origin = t.origin;
1512-
copies = t.copies + 1;
1511+
if (this != &t) {
1512+
origin = t.origin;
1513+
copies = t.copies + 1;
1514+
}
15131515
return *this;
15141516
}
15151517
};

0 commit comments

Comments
 (0)