summaryrefslogtreecommitdiff
path: root/src/util/amount.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-04-02 14:01:41 +0200
committerChristian Grothoff <christian@grothoff.org>2020-04-02 14:01:41 +0200
commite9de3374a974df5e7eeaff0c3241dd98724c642e (patch)
treee5fe6a8edbd622ef26036587f17a1cafb5f10424 /src/util/amount.c
parenta039926bb6f022b1467c7059f0b954b64eaaeb5a (diff)
downloadexchange-e9de3374a974df5e7eeaff0c3241dd98724c642e.tar.gz
exchange-e9de3374a974df5e7eeaff0c3241dd98724c642e.tar.bz2
exchange-e9de3374a974df5e7eeaff0c3241dd98724c642e.zip
fix #6148
Diffstat (limited to 'src/util/amount.c')
-rw-r--r--src/util/amount.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/util/amount.c b/src/util/amount.c
index 2fc786541..454f3080d 100644
--- a/src/util/amount.c
+++ b/src/util/amount.c
@@ -529,26 +529,23 @@ TALER_amount_add (struct TALER_Amount *sum,
int
TALER_amount_normalize (struct TALER_Amount *amount)
{
- int ret;
+ uint32_t overflow;
if (GNUNET_YES != TALER_amount_is_valid (amount))
return GNUNET_SYSERR;
- ret = GNUNET_NO;
- while ( (amount->value != UINT64_MAX) &&
- (amount->fraction >= TALER_AMOUNT_FRAC_BASE) )
- {
- amount->fraction -= TALER_AMOUNT_FRAC_BASE;
- amount->value++;
- ret = GNUNET_OK;
- }
- if (amount->fraction >= TALER_AMOUNT_FRAC_BASE)
+ if (amount->fraction < TALER_AMOUNT_FRAC_BASE)
+ return GNUNET_NO;
+ overflow = amount->fraction / TALER_AMOUT_FRAC_BASE;
+ amount->fraction %= TALER_AMOUNT_FRAC_BASE;
+ amount->value += overflow;
+ ret = GNUNET_OK;
+ if ( (amount->value < overflow) ||
+ (amount->value > MAX_AMOUNT_VALUE) )
{
- /* failed to normalize, adding up fractions caused
- main value to overflow! */
invalidate (amount);
return GNUNET_SYSERR;
}
- return ret;
+ return GNUNET_OK;
}