Skip to content

Commit

Permalink
fix copy assignment operator for unit class to work with refcount
Browse files Browse the repository at this point in the history
This issue was spotted by gfgtdf. It doesn't appear that we
actually use this function -- prior to this commit, I tested a
version which had "assert(false)" at the start of this function,
and it was never triggered in normal play. But it's possible that
some lua command or obscure WML tag does use it.

It might also be a good idea to make the unit class noncopyable.
  • Loading branch information
cbeck88 committed Jul 22, 2014
1 parent 8a94ed7 commit a9879f8
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/unit.cpp
Expand Up @@ -680,8 +680,10 @@ unit& unit::operator=(const unit& u)
{
// Use copy constructor to make sure we are coherent
if (this != &u) {
int old_ref_count = ref_count_;
this->~unit();
new (this) unit(u) ;
ref_count_ = old_ref_count; // TODO: Replace this mess with copy and swap.
}
return *this ;
}
Expand Down

0 comments on commit a9879f8

Please sign in to comment.