Prevent infinite loop in to_decimal if numerator becomes 0.

Also immediately return 0 if this is 0.
This commit is contained in:
John Ralls 2017-07-15 14:59:47 -07:00
parent 9948ee6235
commit 72f95238fb

View File

@ -321,6 +321,10 @@ GncNumeric::to_decimal(unsigned int max_places) const
{ {
if (max_places > max_leg_digits) if (max_places > max_leg_digits)
max_places = max_leg_digits; max_places = max_leg_digits;
if (m_num == 0)
return GncNumeric();
if (is_decimal()) if (is_decimal())
{ {
if (m_num == 0 || m_den < powten(max_places)) if (m_num == 0 || m_den < powten(max_places))
@ -350,7 +354,7 @@ GncNumeric::to_decimal(unsigned int max_places) const
rr_num *= factor; rr_num *= factor;
rr_den *= factor; rr_den *= factor;
} }
while (rr_num % 10 == 0) while (!rr_num.isZero() && rr_num % 10 == 0)
{ {
rr_num /= 10; rr_num /= 10;
rr_den /= 10; rr_den /= 10;