Browse Source

wire/tlvstream: suppress gcc -O3 warning about prev_type.

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 <rusty@rustcorp.com.au>
pull/2938/head
Rusty Russell 5 years ago
committed by Christian Decker
parent
commit
296cfe8d1b
  1. 12
      wire/tlvstream.c

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

Loading…
Cancel
Save