From 5eb121ffc39f741cbc868538593e27c802e7ca0a Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 13 Sep 2020 15:21:57 +0930 Subject: [PATCH] common/amount: fix OpenBSD compile warning. ``` cc common/amount.c common/amount.c:306:15: error: implicit conversion from 'unsigned long long' to 'double' changes value from 18446744073709551615 to 18446744073709551616 [-Werror,-Wimplicit-int-float-conversion] if (scaled > UINT64_MAX) ~ ^~~~~~~~~~ /usr/include/sys/stdint.h:123:21: note: expanded from macro 'UINT64_MAX' ^~~~~~~~~~~~~~~~~~~~~ 1 error generated. gmake: *** [Makefile:254: common/amount.o] Error 1 bsd$ ``` Fixes: #4044 Signed-off-by: Rusty Russell --- common/amount.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/amount.c b/common/amount.c index bf9c74d17..7c1f57d50 100644 --- a/common/amount.c +++ b/common/amount.c @@ -303,7 +303,9 @@ WARN_UNUSED_RESULT bool amount_msat_scale(struct amount_msat *val, { double scaled = sat.millisatoshis * scale; - if (scaled > UINT64_MAX) + /* If mantissa is < 64 bits, a naive "if (scaled > + * UINT64_MAX)" doesn't work. Stick to powers of 2. */ + if (scaled >= (double)((u64)1 << 63) * 2) return false; val->millisatoshis = scaled; return true;