From a3ca3fb047fd79088dbaef5765786f28bab9c875 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 30 Jan 2023 14:59:57 +1030 Subject: [PATCH] common/bolt11: fix 32-bit compilation. Fixes d9fed06b900368e59f4d1f432b87d40fd28ce8d3: ``` common/bolt11.c:868:31: error: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'u64' (aka 'unsigned long long') [-Werror,-Wformat] bech32_charset[type], field_len); ^~~~~~~~~ ``` Signed-off-by: Rusty Russell --- common/bolt11.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/common/bolt11.c b/common/bolt11.c index 4b00e8535..c2c7c3db1 100644 --- a/common/bolt11.c +++ b/common/bolt11.c @@ -826,7 +826,8 @@ struct bolt11 *bolt11_decode_nosig(const tal_t *ctx, const char *str, while (data_len > 520 / 5) { const char *problem = NULL; - u64 type, field_len; + u64 type, field_len64; + size_t field_len; const struct decoder *decoder; /* BOLT #11: @@ -841,15 +842,21 @@ struct bolt11 *bolt11_decode_nosig(const tal_t *ctx, const char *str, if (err) return decode_fail(b11, fail, "Can't get tag: %s", err); - err = pull_uint(&hu5, &data, &data_len, &field_len, 10); + err = pull_uint(&hu5, &data, &data_len, &field_len64, 10); if (err) return decode_fail(b11, fail, "Can't get length: %s", err); /* Can't exceed total data remaining. */ - if (field_len > data_len) + if (field_len64 > data_len) return decode_fail(b11, fail, "%c: truncated", bech32_charset[type]); + + /* These are different types on 32 bit! But since data_len is + * also size_t, above check ensures this will fit. */ + field_len = field_len64; + assert(field_len == field_len64); + /* Do this now: the decode function fixes up the data ptr */ data_len -= field_len;