From 296cfe8d1bec3865556462535d175dfc613dfd9d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 1 Aug 2019 11:04:05 +0930 Subject: [PATCH] wire/tlvstream: suppress gcc -O3 warning about prev_type. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a pointer, so it's explicit and gcc is happy. We avoid the allocation by pointing it to another stack var. ./wire/tlvstream.c:81:22: error: ‘prev_type’ may be used uninitialized in this function [-Werror=maybe-uninitialized] Signed-off-by: Rusty Russell --- wire/tlvstream.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/wire/tlvstream.c b/wire/tlvstream.c index 23c4c75ae..d7bbd85fc 100644 --- a/wire/tlvstream.c +++ b/wire/tlvstream.c @@ -24,8 +24,8 @@ bool fromwire_tlvs(const u8 **cursor, size_t *max, size_t num_types, void *record) { - u64 prev_type; - bool first = true; + /* prev_type points to prev_type_store after first iter. */ + u64 prev_type_store, *prev_type = NULL; /* BOLT-EXPERIMENTAL #1: * @@ -78,8 +78,8 @@ bool fromwire_tlvs(const u8 **cursor, size_t *max, * - if decoded `type`s are not monotonically-increasing: * - MUST fail to parse the `tlv_stream`. */ - if (!first && type <= prev_type) { - if (type == prev_type) + if (prev_type && type <= *prev_type) { + if (type == *prev_type) SUPERVERBOSE("duplicate tlv type"); else SUPERVERBOSE("invalid ordering"); @@ -127,8 +127,8 @@ bool fromwire_tlvs(const u8 **cursor, size_t *max, goto fail; } } - first = false; - prev_type = type; + prev_type = &prev_type_store; + *prev_type = type; } return true;