Closed
Description
bigint.cc contains the following code:
BigInt &
BigInt::operator= (BigInt const &y)
{
if (&y != this)
{
reallocate (y.length);
length = y.length;
positive = y.positive;
memcpy (digit, y.digit, length * sizeof (onedig_t));
}
return *this;
}
inline void
BigInt::reallocate (unsigned digits)
{
if (digits > size)
{
if (size)
delete[] digit;
size = adjust_size (digits);
digit = new onedig_t[size];
}
}
The problem is in these lines:
size = adjust_size (digits);
digit = new onedig_t[size];
If the call to new onedig_t[size]
throws, then the object will be left in an invalid state in which the size
is nonzero, even though digit
doesn't point to a valid location.