Fix compile warnings reading type-0 TLVs
authorMatt Corallo <git@bluematt.me>
Tue, 25 May 2021 20:29:09 +0000 (20:29 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 27 May 2021 01:05:26 +0000 (01:05 +0000)
lightning/src/util/ser_macros.rs

index 87f990a6f0677ee1f2a12735d0d8176ecf3af4d9..30fa60f9742266467b612720d997e2bb808aaec4 100644 (file)
@@ -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)?
+                       }
                })*
        } }
 }