From 72f95238fb56b026fab9d919bb53df96817cc73a Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sat, 15 Jul 2017 14:59:47 -0700 Subject: [PATCH] Prevent infinite loop in to_decimal if numerator becomes 0. Also immediately return 0 if this is 0. --- src/libqof/qof/gnc-numeric.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libqof/qof/gnc-numeric.cpp b/src/libqof/qof/gnc-numeric.cpp index 3e74568c83..8e79cfb2a5 100644 --- a/src/libqof/qof/gnc-numeric.cpp +++ b/src/libqof/qof/gnc-numeric.cpp @@ -321,6 +321,10 @@ GncNumeric::to_decimal(unsigned int max_places) const { if (max_places > max_leg_digits) max_places = max_leg_digits; + + if (m_num == 0) + return GncNumeric(); + if (is_decimal()) { 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_den *= factor; } - while (rr_num % 10 == 0) + while (!rr_num.isZero() && rr_num % 10 == 0) { rr_num /= 10; rr_den /= 10;