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;
}


Bugs Found

Checked Projects
354
Collected Errors
13 290