From 6a9c270776e7a71fb76a52d040f1cd28b257eec7 Mon Sep 17 00:00:00 2001 From: Crypto Brad Garlinghouse Date: Tue, 26 Jul 2022 04:41:01 +0000 Subject: [PATCH] Properly handle self-assignment of PublicKey --- src/ripple/protocol/impl/PublicKey.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/ripple/protocol/impl/PublicKey.cpp b/src/ripple/protocol/impl/PublicKey.cpp index 9fed78088..ac86634f1 100644 --- a/src/ripple/protocol/impl/PublicKey.cpp +++ b/src/ripple/protocol/impl/PublicKey.cpp @@ -24,7 +24,6 @@ #include #include #include -#include namespace ripple { @@ -186,14 +185,18 @@ PublicKey::PublicKey(PublicKey const& other) : size_(other.size_) { if (size_) std::memcpy(buf_, other.buf_, size_); -}; +} PublicKey& PublicKey::operator=(PublicKey const& other) { - size_ = other.size_; - if (size_) - std::memcpy(buf_, other.buf_, size_); + if (this != &other) + { + size_ = other.size_; + if (size_) + std::memcpy(buf_, other.buf_, size_); + } + return *this; }