From d20e5934286a81ebda04834490b4189a891487ad Mon Sep 17 00:00:00 2001 From: Chris Shoemaker Date: Fri, 6 Jan 2006 22:28:38 +0000 Subject: [PATCH] Fix floating point exception by checking for overflow. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@12278 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/app-utils/gnc-ui-util.c | 6 ++++++ src/app-utils/gnc-ui-util.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/app-utils/gnc-ui-util.c b/src/app-utils/gnc-ui-util.c index 21f958cfce..9a577399e1 100644 --- a/src/app-utils/gnc-ui-util.c +++ b/src/app-utils/gnc-ui-util.c @@ -1189,6 +1189,12 @@ 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_DENOM_LCD); + /* Yes, rounding up can cause overflow. Check for it. */ + if (gnc_numeric_check(val)) { + PWARN("Bad numeric from rounding."); + *buf = '\0'; + return 0; + } } /* calculate the integer part and the remainder */ diff --git a/src/app-utils/gnc-ui-util.h b/src/app-utils/gnc-ui-util.h index 77a9e8b90a..aa2d23b4e1 100644 --- a/src/app-utils/gnc-ui-util.h +++ b/src/app-utils/gnc-ui-util.h @@ -295,6 +295,9 @@ GNCPrintAmountInfo gnc_default_price_print_info (void); GNCPrintAmountInfo gnc_integral_print_info (void); +/* WARNING: Garbage in, garbage out. You must check the validity of + the supplied gnc_numeric. If it's invalid, the returned string + could point to ANYTHING. */ const char * xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info); int xaccSPrintAmount (char *buf, gnc_numeric val, GNCPrintAmountInfo info);