Properly handle self-assignment of PublicKey

This commit is contained in:
Crypto Brad Garlinghouse
2022-07-26 04:41:01 +00:00
committed by Nik Bougalis
parent 21a3f4a5b5
commit 6a9c270776

View File

@@ -24,7 +24,6 @@
#include <ripple/protocol/impl/secp256k1.h> #include <ripple/protocol/impl/secp256k1.h>
#include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_int.hpp>
#include <ed25519-donna/ed25519.h> #include <ed25519-donna/ed25519.h>
#include <type_traits>
namespace ripple { namespace ripple {
@@ -186,14 +185,18 @@ PublicKey::PublicKey(PublicKey const& other) : size_(other.size_)
{ {
if (size_) if (size_)
std::memcpy(buf_, other.buf_, size_); std::memcpy(buf_, other.buf_, size_);
}; }
PublicKey& PublicKey&
PublicKey::operator=(PublicKey const& other) PublicKey::operator=(PublicKey const& other)
{ {
size_ = other.size_; if (this != &other)
if (size_) {
std::memcpy(buf_, other.buf_, size_); size_ = other.size_;
if (size_)
std::memcpy(buf_, other.buf_, size_);
}
return *this; return *this;
} }