From c889976d03f70142b3b534640ebf7a395e22262b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 14 Aug 2023 17:09:47 +0930 Subject: [PATCH] common: fix gcc-12.3.0 -O3 warning. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is actually a valid complaint (though this is a sanity check for things we make ourselves, still!). ``` In file included from common/test/run-blindedpath_onion.c:9: common/test/../sphinx.c: In function ‘sphinx_add_hop_has_length’: common/test/../sphinx.c:117:12: error: ‘prepended_len’ may be used uninitialized [-Werror=maybe-uninitialized] 117 | if (lenlen + prepended_len != tal_bytelen(payload)) | ^ common/test/../sphinx.c:109:27: note: ‘prepended_len’ was declared here 109 | bigsize_t lenlen, prepended_len; | ^~~~~~~~~~~~~ cc1: all warnings being treated as errors ``` Signed-off-by: Rusty Russell --- common/sphinx.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/common/sphinx.c b/common/sphinx.c index d908f622e..4b0fa2e70 100644 --- a/common/sphinx.c +++ b/common/sphinx.c @@ -108,9 +108,8 @@ bool sphinx_add_hop_has_length(struct sphinx_path *path, const struct pubkey *pu struct sphinx_hop sp; bigsize_t lenlen, prepended_len; - /* You promised size was prepended! */ - if (tal_bytelen(payload) == 0) - return false; + /* In case length is missing, we'll return false. */ + prepended_len = UINT64_MAX; lenlen = bigsize_get(payload, tal_bytelen(payload), &prepended_len); if (add_overflows_u64(lenlen, prepended_len)) return false;