exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit f0114f84d8e4aa3d36c839a84dccae6c24c70c68
parent 659fa343d8634b0d81e77f69f44278aa145242a8
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 11 Oct 2026 14:53:05 +0200

handle extreme float values/NaN

Diffstat:
Msrc/lib/exchange_api_stefan.c | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/lib/exchange_api_stefan.c b/src/lib/exchange_api_stefan.c @@ -85,6 +85,23 @@ double_to_amount (double dv, GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (currency, rval)); + if (! (dv > 0.0)) + { + /* Negative or NaN: converting this to the unsigned @e value + would be undefined behaviour; the zero amount is the best + (and safe) answer here. */ + GNUNET_break (0); + return; + } + if (dv >= (double) TALER_AMOUNT_MAX_VALUE) + { + /* Out of range for a Taler amount; saturate instead of + invoking undefined behaviour in the conversion below. */ + GNUNET_break (0); + rval->value = TALER_AMOUNT_MAX_VALUE - 1; + rval->fraction = TALER_AMOUNT_FRAC_BASE - 1; + return; + } rval->value = floorl (dv); rem = dv - ((double) rval->value); if (rem < 0.0)