image : fix buffer's copy ctor - only std::copy when rhs owns the data (#3152)

This commit is contained in:
artemp 2015-10-30 16:47:26 +00:00
parent 34f5b56003
commit cb31692f37

View file

@ -59,10 +59,11 @@ buffer::buffer(buffer && rhs) noexcept
// copy
buffer::buffer(buffer const& rhs)
: size_(rhs.size_),
data_(static_cast<unsigned char*>(size_ != 0 ? ::operator new(size_) : nullptr)),
owns_(true)
data_(static_cast<unsigned char*>((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()