Calling sigfigs_denom with a zero crashes due to a divide by zero.

This commit is contained in:
Mike Alexander 2017-04-04 01:58:32 -04:00
parent 6933ab765d
commit cdc94c7131
2 changed files with 6 additions and 0 deletions

View File

@ -280,6 +280,9 @@ GncNumeric::prepare_conversion(int64_t new_denom) const
int64_t
GncNumeric::sigfigs_denom(unsigned figs) const noexcept
{
if (m_num == 0)
return 1;
int64_t num_abs{std::abs(m_num)};
bool not_frac = num_abs > m_den;
int64_t val{ not_frac ? num_abs / m_den : m_den / num_abs };

View File

@ -159,6 +159,9 @@ GncRational::prepare_conversion (GncInt128 new_denom) const
GncInt128
GncRational::sigfigs_denom(unsigned figs) const noexcept
{
if (m_num == 0)
return 1;
auto num_abs = m_num.abs();
bool not_frac = num_abs > m_den;
int64_t val{ not_frac ? num_abs / m_den : m_den / num_abs };