BigInteger: guard against self-assignment

Related-to: #404.
Suggested-by: @cosinekitty
This commit is contained in:
Philipp A. Hartmann 2015-08-13 23:07:30 +02:00
parent 3cf7228f46
commit afbc0406f0

View File

@ -54,8 +54,10 @@ public:
BigInteger& operator=(const BigInteger &rhs)
{
count_ = rhs.count_;
std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type));
if (this != &rhs) {
count_ = rhs.count_;
std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type));
}
return *this;
}