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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2020-09-13 15:21:57 +09:30
parent ea810b7011
commit 5eb121ffc3

View File

@ -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;