Examples of errors detected by the V794 diagnostic
V794. The assignment operator should be protected from the case of 'this == &src'.
Chromium
V794 The copy operator should be protected from the case of 'this == &other'. vector_buffer.h 59
VectorBuffer& operator=(VectorBuffer&& other) {
free(buffer_);
buffer_ = other.buffer_;
capacity_ = other.capacity_;
other.buffer_ = nullptr;
other.capacity_ = 0;
return *this;
}
There is no protection in case the object is moved within itself.
Similar errors can be found in some other places:
- V794 The copy operator should be protected from the case of 'this == &other'. gurl.cc 138
- V794 The copy operator should be protected from the case of 'this == &other'. spdy_protocol.h 890
- V794 The copy operator should be protected from the case of 'this == &other'. crypto_handshake_message.cc 41
- And 6 additional diagnostic messages.
ANGLE
V794 The copy operator should be protected from the case of 'this == &other'. error.inl 56
Error &Error::operator=(const Error &other)
{
mCode = other.mCode;
mID = other.mID;
if (other.mMessage)
{
createMessageString();
*mMessage = *(other.mMessage);
}
else
{
mMessage.release();
}
return *this;
}
There is no protection for the case when the object is copied in itself.
Similar errors can be found in some other places:
- V794 The copy operator should be protected from the case of 'this == &other'. error.inl 145
- V794 The copy operator should be protected from the case of 'this == &t'. types.cpp 250
RE2
V794 The copy operator should be protected from the case of 'this == &src'. sparse_array.h 362
template<typename Value>
SparseArray<Value>& SparseArray<Value>::operator=(
const SparseArray& src)
{
size_ = src.size_;
max_size_ = src.max_size_;
std::unique_ptr<int[]> a(new int[max_size_]);
std::copy_n(src.sparse_.get(), src.max_size_, a.get());
sparse_ = std::move(a);
std::unique_ptr<IndexValue[]> b(new IndexValue[max_size_]);
std::copy_n(src.dense_.get(), src.max_size_, b.get());
dense_ = std::move(b);
return *this;
}
There is no protection for the case when the object is copied in itself.
WebRTC
V794 The copy operator should be protected from the case of 'this == &other'. desktop_region.cc 50
DesktopRegion& DesktopRegion::operator=(
const DesktopRegion& other)
{
Clear();
rows_ = other.rows_;
for (Rows::iterator it = rows_.begin();
it != rows_.end(); ++it) {
// Copy each row.
Row* row = it->second;
it->second = new Row(*row);
}
return *this;
}
There is no protection for the case when the object is copied in itself.
EA WebKit
V794 The copy operator should be protected from the case of 'this == &other'. transformstate.cpp 30
TransformState& TransformState::operator=(
const TransformState& other)
{
accumulated_offset_ = other.accumulated_offset_;
map_point_ = other.map_point_;
map_quad_ = other.map_quad_;
if (map_point_)
last_planar_point_ = other.last_planar_point_;
if (map_quad_)
last_planar_quad_ = other.last_planar_quad_;
accumulating_transform_ = other.accumulating_transform_;
force_accumulating_transform_ =
other.force_accumulating_transform_;
direction_ = other.direction_;
accumulated_transform_.reset();
if (other.accumulated_transform_)
accumulated_transform_ =
TransformationMatrix::Create(*other.accumulated_transform_);
return *this;
}
There is no protection for the case when the object is copied in itself.
TDLib
V794 The assignment operator should be protected from the case of 'this == &other'. status.h 340
Result &operator=(Result &&other) {
if (status_.is_ok()) {
value_.~T();
}
if (other.status_.is_ok()) {
....
new (&value_) T(std::move(other.value_));
....
other.value_.~T();
}
status_ = std::move(other.status_);
other.status_ = Status::Error();
return *this;
}
Android
V794 The assignment operator should be protected from the case of 'this == &other'. HidlSupport.h 421
hidl_vec &operator=(hidl_vec &&other) noexcept {
if (mOwnsBuffer) {
delete[] mBuffer;
}
mBuffer = other.mBuffer;
mSize = other.mSize;
mOwnsBuffer = other.mOwnsBuffer;
other.mOwnsBuffer = false;
return *this;
}
LibreOffice
V794 The assignment operator should be protected from the case of 'this == &rToBeCopied'. hommatrixtemplate.hxx 121
ImplHomMatrixTemplate& operator=(....)
{
// complete initialization using copy
for(sal_uInt16 a(0); a < (RowSize - 1); a++)
{
memcpy(&maLine[a], &rToBeCopied.maLine[a], sizeof(....));
}
if(rToBeCopied.mpLine)
{
mpLine.reset( new ImplMatLine< RowSize >(....) );
}
return *this;
}
SpeedCrunch
V794 The assignment operator should be protected from the case of 'this == &other'. quantity.cpp 373
Quantity& Quantity::operator=(const Quantity& other)
{
m_numericValue = other.m_numericValue;
m_dimension = other.m_dimension;
m_format = other.m_format;
stripUnits();
if(other.hasUnit()) {
m_unit = new CNumber(*other.m_unit);
m_unitName = other.m_unitName;
}
cleanDimension();
return *this;
}
CARLA
V794 The assignment operator should be protected from the case of 'this == &other'. cpp11_zone.hpp 92
struct finalizer_array
{
void call() {
finalizer* fin = m_tail;
for(; fin != m_array; --fin) (*(fin-1))();
}
~finalizer_array() {
call();
::free(m_array);
}
finalizer_array& operator=(finalizer_array&& other) noexcept
{
this->~finalizer_array(); // <=
new (this) finalizer_array(std::move(other));
return *this;
}
finalizer_array(finalizer_array&& other) noexcept
: m_tail(other.m_tail), m_end(other.m_end), m_array(other.m_array)
{
other.m_tail = MSGPACK_NULLPTR;
other.m_end = MSGPACK_NULLPTR;
other.m_array = MSGPACK_NULLPTR;
}
....
finalizer* m_tail;
finalizer* m_end;
finalizer* m_array;
}
GPCS4
V794 The assignment operator should be protected from the case of 'this == &other'. VltShader.cpp 39
VltShaderConstData& VltShaderConstData::operator=(VltShaderConstData&& other)
{
delete[] m_data;
this->m_size = other.m_size;
this->m_data = other.m_data;
other.m_size = 0;
other.m_data = nullptr;
return *this;
}
VCMI
V794 The assignment operator should be protected from the case of 'this == &rhs'. ObjectTemplate.cpp 88
ObjectTemplate & ObjectTemplate::operator=(const ObjectTemplate & rhs)
{
....
width = rhs.width;
height = rhs.height;
visitable = rhs.visitable;
blockedOffsets = rhs.blockedOffsets;
blockMapOffset = rhs.blockMapOffset;
visitableOffset = rhs.visitableOffset;
usedTiles.clear();
usedTiles.resize(rhs.usedTiles.size());
for(size_t i = 0; i < usedTiles.size(); i++)
std::copy(....);
return *this;
}