Commit 1f4a6986 authored by Dominik Charousset's avatar Dominik Charousset

Protect against self-assignment, close #1169

parent f71e95d7
......@@ -39,7 +39,9 @@ error::error(const error& x) : data_(x ? new data(*x.data_) : nullptr) {
}
error& error::operator=(const error& x) {
if (x) {
if (this == &x) {
// nop
} else if (x) {
if (data_ == nullptr)
data_.reset(new data(*x.data_));
else
......
......@@ -131,6 +131,7 @@ bool load_data(Deserializer& source, message::data_ptr& data) {
swap(meta, other.meta);
}
object_ptr& operator=(object_ptr&& other) noexcept {
if (this != &other) {
if (obj) {
meta->destroy(obj);
free(obj);
......@@ -140,6 +141,7 @@ bool load_data(Deserializer& source, message::data_ptr& data) {
using std::swap;
swap(obj, other.obj);
swap(meta, other.meta);
}
return *this;
}
~object_ptr() noexcept {
......
......@@ -62,9 +62,11 @@ ip_endpoint::ip_endpoint(const ip_endpoint& other) {
}
ip_endpoint& ip_endpoint::operator=(const ip_endpoint& other) {
if (this != &other) {
ptr_.reset(new ip_endpoint::impl);
memcpy(address(), other.caddress(), sizeof(sockaddr_storage));
*length() = *other.clength();
}
return *this;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment