diff --git a/src/arith_uint256.h b/src/arith_uint256.h index ba36cebbdcc..955fd655632 100644 --- a/src/arith_uint256.h +++ b/src/arith_uint256.h @@ -43,8 +43,10 @@ public: base_uint& operator=(const base_uint& b) { - for (int i = 0; i < WIDTH; i++) - pn[i] = b.pn[i]; + if (this != &b) { + for (int i = 0; i < WIDTH; i++) + pn[i] = b.pn[i]; + } return *this; } diff --git a/src/key.h b/src/key.h index c802e1ebb8c..bbca2c4deef 100644 --- a/src/key.h +++ b/src/key.h @@ -75,13 +75,15 @@ public: CKey& operator=(const CKey& other) { - if (other.keydata) { - MakeKeyData(); - *keydata = *other.keydata; - } else { - ClearKeyData(); + if (this != &other) { + if (other.keydata) { + MakeKeyData(); + *keydata = *other.keydata; + } else { + ClearKeyData(); + } + fCompressed = other.fCompressed; } - fCompressed = other.fCompressed; return *this; } diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index a371753adf0..1b66496505b 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -1508,8 +1508,10 @@ struct Tracker Tracker(Tracker&& t) noexcept : origin(t.origin), copies(t.copies) {} Tracker& operator=(const Tracker& t) noexcept { - origin = t.origin; - copies = t.copies + 1; + if (this != &t) { + origin = t.origin; + copies = t.copies + 1; + } return *this; } };