From: Matt Corallo Date: Tue, 25 May 2021 20:29:09 +0000 (+0000) Subject: Fix compile warnings reading type-0 TLVs X-Git-Tag: v0.0.98~14^2~8 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=c9f6a35756b8418ed6fbeb48bc23cc19b42a9134;p=rust-lightning Fix compile warnings reading type-0 TLVs --- diff --git a/lightning/src/util/ser_macros.rs b/lightning/src/util/ser_macros.rs index 87f990a6f..30fa60f97 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)? + } })* } } }