From c9f6a35756b8418ed6fbeb48bc23cc19b42a9134 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 25 May 2021 20:29:09 +0000 Subject: [PATCH 1/1] Fix compile warnings reading type-0 TLVs --- lightning/src/util/ser_macros.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lightning/src/util/ser_macros.rs b/lightning/src/util/ser_macros.rs index 87f990a6..30fa60f9 100644 --- a/lightning/src/util/ser_macros.rs +++ b/lightning/src/util/ser_macros.rs @@ -115,8 +115,12 @@ macro_rules! decode_tlv { _ => {}, } // As we read types, make sure we hit every required type: - $(if (last_seen_type.is_none() || last_seen_type.unwrap() < $reqtype) && typ.0 > $reqtype { - Err(DecodeError::InvalidValue)? + $({ + #[allow(unused_comparisons)] // Note that $reqtype may be 0 making the second comparison always true + let invalid_order = (last_seen_type.is_none() || last_seen_type.unwrap() < $reqtype) && typ.0 > $reqtype; + if invalid_order { + Err(DecodeError::InvalidValue)? + } })* last_seen_type = Some(typ.0); @@ -146,8 +150,12 @@ macro_rules! decode_tlv { s.eat_remaining()?; } // Make sure we got to each required type after we've read every TLV: - $(if last_seen_type.is_none() || last_seen_type.unwrap() < $reqtype { - Err(DecodeError::InvalidValue)? + $({ + #[allow(unused_comparisons)] // Note that $reqtype may be 0 making the second comparison always true + let missing_req_type = last_seen_type.is_none() || last_seen_type.unwrap() < $reqtype; + if missing_req_type { + Err(DecodeError::InvalidValue)? + } })* } } } -- 2.30.2