Skip to content

Commit 5eb121f

Browse files
committed
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 <[email protected]>
1 parent ea810b7 commit 5eb121f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

common/amount.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ WARN_UNUSED_RESULT bool amount_msat_scale(struct amount_msat *val,
303303
{
304304
double scaled = sat.millisatoshis * scale;
305305

306-
if (scaled > UINT64_MAX)
306+
/* If mantissa is < 64 bits, a naive "if (scaled >
307+
* UINT64_MAX)" doesn't work. Stick to powers of 2. */
308+
if (scaled >= (double)((u64)1 << 63) * 2)
307309
return false;
308310
val->millisatoshis = scaled;
309311
return true;

0 commit comments

Comments
 (0)