mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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.
This commit is contained in:
parent
701d8030b8
commit
b694df7202
@ -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.",
|
||||
|
Loading…
Reference in New Issue
Block a user