From 66f4d5b57afb555ec1e1365d75f8566826713a47 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Tue, 11 Feb 2014 05:42:51 +0400 Subject: [PATCH] Properly handle self-assignment --- SDL2pp/Point.cc | 8 ++++++-- SDL2pp/Rect.cc | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/SDL2pp/Point.cc b/SDL2pp/Point.cc index 532c0a1..5cdfd8a 100644 --- a/SDL2pp/Point.cc +++ b/SDL2pp/Point.cc @@ -43,7 +43,9 @@ Point Point::Null() { } Point::Point(const Point& other) { - if (other.point_.get()) { + if (!other.point_) { + point_.reset(nullptr); + } else if (point_ != other.point_) { point_.reset(new SDL_Point); point_->x = other.point_->x; point_->y = other.point_->y; @@ -53,7 +55,9 @@ Point::Point(const Point& other) { Point::Point(Point&&) noexcept = default; Point& Point::operator=(const Point& other) { - if (other.point_.get()) { + if (!other.point_) { + point_.reset(nullptr); + } else if (point_ != other.point_) { point_.reset(new SDL_Point); point_->x = other.point_->x; point_->y = other.point_->y; diff --git a/SDL2pp/Rect.cc b/SDL2pp/Rect.cc index 7f1d7b5..c5a3f41 100644 --- a/SDL2pp/Rect.cc +++ b/SDL2pp/Rect.cc @@ -45,7 +45,9 @@ Rect Rect::Null() { } Rect::Rect(const Rect& other) { - if (other.rect_.get()) { + if (!other.rect_) { + rect_.reset(nullptr); + } else if (rect_ != other.rect_) { rect_.reset(new SDL_Rect); rect_->x = other.rect_->x; rect_->y = other.rect_->y; @@ -57,7 +59,9 @@ Rect::Rect(const Rect& other) { Rect::Rect(Rect&&) noexcept = default; Rect& Rect::operator=(const Rect& other) { - if (other.rect_.get()) { + if (!other.rect_) { + rect_.reset(nullptr); + } else if (rect_ != other.rect_) { rect_.reset(new SDL_Rect); rect_->x = other.rect_->x; rect_->y = other.rect_->y;