Skip to content

Commit bc290aa

Browse files
committed
Fix compile warnings reading type-0 TLVs
1 parent 0065308 commit bc290aa

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lightning/src/util/ser_macros.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,12 @@ macro_rules! decode_tlv {
115115
_ => {},
116116
}
117117
// As we read types, make sure we hit every required type:
118-
$(if (last_seen_type.is_none() || last_seen_type.unwrap() < $reqtype) && typ.0 > $reqtype {
119-
Err(DecodeError::InvalidValue)?
118+
$({
119+
#[allow(unused_comparisons)] // Note that $reqtype may be 0 making the second comparison always true
120+
let invalid_order = (last_seen_type.is_none() || last_seen_type.unwrap() < $reqtype) && typ.0 > $reqtype;
121+
if invalid_order {
122+
Err(DecodeError::InvalidValue)?
123+
}
120124
})*
121125
last_seen_type = Some(typ.0);
122126

@@ -146,8 +150,12 @@ macro_rules! decode_tlv {
146150
s.eat_remaining()?;
147151
}
148152
// Make sure we got to each required type after we've read every TLV:
149-
$(if last_seen_type.is_none() || last_seen_type.unwrap() < $reqtype {
150-
Err(DecodeError::InvalidValue)?
153+
$({
154+
#[allow(unused_comparisons)] // Note that $reqtype may be 0 making the second comparison always true
155+
let missing_req_type = last_seen_type.is_none() || last_seen_type.unwrap() < $reqtype;
156+
if missing_req_type {
157+
Err(DecodeError::InvalidValue)?
158+
}
151159
})*
152160
} }
153161
}

0 commit comments

Comments
 (0)