Browse Source

Merge pull request #2778 from LianaHus/check_for_this_in_constructors

added checks to prevent the self assignment
cl-refactor
Gav Wood 10 years ago
parent
commit
f9677e6267
  1. 10
      libdevcore/Common.h
  2. 7
      libdevcore/Worker.h
  3. 3
      libethereum/Block.cpp
  4. 3
      libethereum/State.cpp
  5. 1
      libethereum/TransactionQueue.cpp
  6. 9
      libethereum/TransactionQueue.h
  7. 2
      libethereum/VerifiedBlock.h
  8. 17
      libevmasm/SourceLocation.h
  9. 8
      libp2p/Common.h
  10. 2
      libsolidity/Types.cpp

10
libdevcore/Common.h

@ -92,7 +92,15 @@ public:
explicit secure_vector(vector_ref<const T> _c): m_data(_c.data(), _c.data() + _c.size()) {}
~secure_vector() { ref().cleanse(); }
secure_vector<T>& operator=(secure_vector<T> const& _c) { ref().cleanse(); m_data = _c.m_data; return *this; }
secure_vector<T>& operator=(secure_vector<T> const& _c)
{
if (&_c == this)
return *this;
ref().cleanse();
m_data = _c.m_data;
return *this;
}
std::vector<T>& writable() { clear(); return m_data; }
std::vector<T> const& makeInsecure() const { return m_data; }

7
libdevcore/Worker.h

@ -54,7 +54,12 @@ protected:
Worker(Worker&& _m) { std::swap(m_name, _m.m_name); }
/// Move-assignment.
Worker& operator=(Worker&& _m) { std::swap(m_name, _m.m_name); return *this; }
Worker& operator=(Worker&& _m)
{
assert(&_m != this);
std::swap(m_name, _m.m_name);
return *this;
}
virtual ~Worker() { terminate(); }

3
libethereum/Block.cpp

@ -80,6 +80,9 @@ Block::Block(Block const& _s):
Block& Block::operator=(Block const& _s)
{
if (&_s == this)
return *this;
m_state = _s.m_state;
m_transactions = _s.m_transactions;
m_receipts = _s.m_receipts;

3
libethereum/State.cpp

@ -136,6 +136,9 @@ void State::paranoia(std::string const& _when, bool _enforceRefs) const
State& State::operator=(State const& _s)
{
if (&_s == this)
return *this;
m_db = _s.m_db;
m_state.open(&m_db, _s.m_state.root(), Verification::Skip);
m_cache = _s.m_cache;

1
libethereum/TransactionQueue.cpp

@ -402,4 +402,3 @@ void TransactionQueue::verifierBody()
}
}
}

9
libethereum/TransactionQueue.h

@ -140,7 +140,14 @@ private:
UnverifiedTransaction() {}
UnverifiedTransaction(bytesConstRef const& _t, h512 const& _nodeId): transaction(_t.toBytes()), nodeId(_nodeId) {}
UnverifiedTransaction(UnverifiedTransaction&& _t): transaction(std::move(_t.transaction)) {}
UnverifiedTransaction& operator=(UnverifiedTransaction&& _other) { transaction = std::move(_other.transaction); nodeId = std::move(_other.nodeId); return *this; }
UnverifiedTransaction& operator=(UnverifiedTransaction&& _other)
{
assert(&_other != this);
transaction = std::move(_other.transaction);
nodeId = std::move(_other.nodeId);
return *this;
}
UnverifiedTransaction(UnverifiedTransaction const&) = delete;
UnverifiedTransaction& operator=(UnverifiedTransaction const&) = delete;

2
libethereum/VerifiedBlock.h

@ -58,6 +58,8 @@ struct VerifiedBlock
VerifiedBlock& operator=(VerifiedBlock&& _other)
{
assert(&_other != this);
verified = (std::move(_other.verified));
blockData = (std::move(_other.blockData));
return *this;

17
libevmasm/SourceLocation.h

@ -41,8 +41,21 @@ struct SourceLocation
SourceLocation(): start(-1), end(-1) { }
SourceLocation(SourceLocation const& _other):
start(_other.start), end(_other.end), sourceName(_other.sourceName) {}
SourceLocation& operator=(SourceLocation const& _other) { start = _other.start; end = _other.end; sourceName = _other.sourceName; return *this;}
start(_other.start),
end(_other.end),
sourceName(_other.sourceName)
{}
SourceLocation& operator=(SourceLocation const& _other)
{
if (&_other == this)
return *this;
start = _other.start;
end = _other.end;
sourceName = _other.sourceName;
return *this;
}
bool operator==(SourceLocation const& _other) const { return start == _other.start && end == _other.end;}
bool operator!=(SourceLocation const& _other) const { return !operator==(_other); }

8
libp2p/Common.h

@ -224,7 +224,13 @@ class DeadlineOps
~DeadlineOp() {}
DeadlineOp(DeadlineOp&& _s): m_timer(_s.m_timer.release()) {}
DeadlineOp& operator=(DeadlineOp&& _s) { m_timer.reset(_s.m_timer.release()); return *this; }
DeadlineOp& operator=(DeadlineOp&& _s)
{
assert(&_s != this);
m_timer.reset(_s.m_timer.release());
return *this;
}
bool expired() { Guard l(x_timer); return m_timer->expires_from_now().total_nanoseconds() <= 0; }
void wait() { Guard l(x_timer); m_timer->wait(); }

2
libsolidity/Types.cpp

@ -79,6 +79,8 @@ pair<u256, unsigned> const* StorageOffsets::getOffset(size_t _index) const
MemberList& MemberList::operator=(MemberList&& _other)
{
assert(&_other != this);
m_memberTypes = std::move(_other.m_memberTypes);
m_storageOffsets = std::move(_other.m_storageOffsets);
return *this;

Loading…
Cancel
Save