From cb31692f3794259876b554ab96ac79a5b87508cf Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 30 Oct 2015 16:47:26 +0000 Subject: [PATCH] image : fix buffer's copy ctor - only std::copy when rhs owns the data (#3152) --- src/image.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/image.cpp b/src/image.cpp index 32c843388..5141860b7 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -59,10 +59,11 @@ buffer::buffer(buffer && rhs) noexcept // copy buffer::buffer(buffer const& rhs) : size_(rhs.size_), - data_(static_cast(size_ != 0 ? ::operator new(size_) : nullptr)), - owns_(true) + data_(static_cast((rhs.owns_ && size_ != 0) ? ::operator new(size_) : nullptr)), + owns_(rhs.owns_) { if (data_) std::copy(rhs.data_, rhs.data_ + rhs.size_, data_); + else data_ = rhs.data_; } buffer::~buffer()