mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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:
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user