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
This commit is contained in:
Chris Shoemaker
2006-01-06 22:28:38 +00:00
parent 8b487afd7b
commit d20e593428
2 changed files with 9 additions and 0 deletions

View File

@@ -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 */

View File

@@ -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);