Catch std::underflow_error as well as std::overflow_error.

Any operation that can overflow will throw an underflow if it's a
negative number. The C interface needs to catch both to prevent
unhandled exception crashes,
This commit is contained in:
John Ralls 2018-09-21 14:28:49 -07:00
parent 6d2ef90313
commit 87533fe4bc

View File

@ -391,6 +391,13 @@ GncNumeric::to_decimal(unsigned int max_places) const
<< " overflows when attempting to convert it to decimal.\n";
throw std::range_error(msg.str());
}
catch (const std::underflow_error& err)
{
std::ostringstream msg;
msg << "GncNumeric " << *this
<< " underflows when attempting to convert it to decimal.\n";
throw std::range_error(msg.str());
}
}
void
@ -998,6 +1005,10 @@ gnc_numeric_convert(gnc_numeric in, int64_t denom, int how)
{
return gnc_numeric_error(GNC_ERROR_OVERFLOW);
}
catch (const std::underflow_error& err)
{
return gnc_numeric_error(GNC_ERROR_OVERFLOW);
}
}