Skip to content

Commit d84ee82

Browse files
Apply review comments
1 parent 04d810d commit d84ee82

File tree

6 files changed

+16
-22
lines changed

6 files changed

+16
-22
lines changed

rust/c509-certificate/src/attributes/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,9 @@ impl Encode<()> for Attributes {
6262
));
6363
}
6464
// The attribute type should be included in array too
65-
let Some(len) = (self.0.len() as u64).checked_mul(2) else {
66-
return Err(minicbor::encode::Error::message(
67-
"Attributes length overflow",
68-
));
69-
};
65+
let len = (self.0.len() as u64)
66+
.checked_mul(2)
67+
.ok_or_else(|| minicbor::encode::Error::message("Attributes length overflow"))?;
7068
encode_array_len(e, "Attributes", len)?;
7169
for attribute in &self.0 {
7270
attribute.encode(e, ctx)?;

rust/c509-certificate/src/general_names/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,9 @@ impl Encode<()> for GeneralNames {
5959
));
6060
}
6161
// The general name type should be included in array too
62-
let Some(len) = (self.0.len() as u64).checked_mul(2) else {
63-
return Err(minicbor::encode::Error::message(
64-
"General Names length overflow",
65-
));
66-
};
62+
let len = (self.0.len() as u64)
63+
.checked_mul(2)
64+
.ok_or_else(|| minicbor::encode::Error::message("General Names length overflow"))?;
6765
encode_array_len(e, "General Names", len)?;
6866
for gn in &self.0 {
6967
gn.encode(e, ctx)?;

rust/c509-certificate/src/name/mod.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,19 @@ impl Encode<()> for NameValue {
106106

107107
encode_cn_value(e, cn_value)?;
108108
} else {
109-
let Some(len) = (attrs.len() as u64).checked_mul(2) else {
110-
return Err(minicbor::encode::Error::message(
111-
"Attribute length overflow",
112-
));
113-
};
109+
let len = (attrs.len() as u64).checked_mul(2).ok_or_else(|| {
110+
minicbor::encode::Error::message("Attribute length overflow")
111+
})?;
114112
encode_array_len(e, "Attributes", len)?;
115113
for attribute in attrs {
116114
attribute.encode(e, ctx)?;
117115
}
118116
}
119117
} else {
120118
// If is okay if the attributes is empty
121-
let Some(len) = (attrs.len() as u64).checked_mul(2) else {
122-
return Err(minicbor::encode::Error::message(
123-
"Attribute length overflow",
124-
));
125-
};
119+
let len = (attrs.len() as u64).checked_mul(2).ok_or_else(|| {
120+
minicbor::encode::Error::message("Attribute length overflow")
121+
})?;
126122
encode_array_len(e, "Attributes", len)?;
127123
for attribute in attrs {
128124
attribute.encode(e, ctx)?;

rust/cardano-chain-follower/examples/follow_chains.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ async fn start_sync_for(network: &Network, matches: ArgMatches) -> Result<(), Bo
9797

9898
if let Some(chunk_size) = matches.get_one::<u16>("mithril-sync-chunk-size") {
9999
let chunk_size = (*chunk_size as usize)
100-
.checked_mul(1024)
101-
.and_then(|v| v.checked_mul(1024))
100+
// 1024 * 1024
101+
.checked_mul(1_048_576)
102102
.ok_or("Chunk size overflow")?;
103103
dl_config = dl_config.with_chunk_size(chunk_size);
104104
}

rust/cardano-chain-follower/src/chain_sync.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ async fn process_rollback(
193193
let head_slot = previous_point.slot_or_default();
194194
debug!("Head slot: {head_slot:?}");
195195
debug!("Rollback slot: {rollback_slot:?}");
196+
// It is ok because slot implement saturating subtraction.
196197
#[allow(clippy::arithmetic_side_effects)]
197198
let slot_rollback_size = head_slot - rollback_slot;
198199

rust/cardano-chain-follower/src/mithril_snapshot_iterator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub(crate) fn probe_point(point: &Point, distance: u64) -> Point {
5656
const STEP_BACK_ORIGIN: u64 = 0;
5757
// Now that we have the tip, step back about 4 block intervals from tip, and do a fuzzy
5858
// iteration to find the exact two blocks at the end of the immutable chain.
59+
// It is ok because slot implement saturating subtraction.
5960
#[allow(clippy::arithmetic_side_effects)]
6061
let step_back_search = point.slot_or_default() - distance.into();
6162

0 commit comments

Comments
 (0)