From b694df72020b43d63fce1d4bfa673e7ea9a42e43 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Wed, 3 Dec 2014 10:18:03 -0800 Subject: [PATCH] Prevent overflow. LCD denom was equivalent to using rounding.denom, which is val.denom * 10. If val.num was at the max # of digits that would overflow, so instead fix val.denom and actually round the result; since we're adding 5/(val.denom * 10) to accomplish the rounding we want to truncate the result. --- src/app-utils/gnc-ui-util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app-utils/gnc-ui-util.c b/src/app-utils/gnc-ui-util.c index 668e1b4261..73f3bd85fb 100644 --- a/src/app-utils/gnc-ui-util.c +++ b/src/app-utils/gnc-ui-util.c @@ -1258,8 +1258,8 @@ PrintAmountInternal(char *buf, gnc_numeric val, const GNCPrintAmountInfo *info) { rounding.num = 5; /* Limit the denom to 10^13 ~= 2^44, leaving max at ~524288 */ rounding.denom = pow(10, max_dp + 1); - val = gnc_numeric_add(val, rounding, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD); - /* Yes, rounding up can cause overflow. Check for it. */ + val = gnc_numeric_add(val, rounding, val.denom, GNC_HOW_RND_TRUNC); + if (gnc_numeric_check(val)) { PWARN ("Bad numeric from rounding: %s.",