Skip to content

Commit 36f3529

Browse files
authored
Simplify a range usage and add some safety comments
1 parent 0b5f5a7 commit 36f3529

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

crates/archive/src/tarball.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,11 @@ impl Archive for Tarball {
115115
/// more efficient than simply downloading the entire file up front.
116116
fn fetch_isize(url: &str, len: u64) -> Result<[u8; 4], ArchiveError> {
117117
let mut header_values = Vec::with_capacity(1);
118-
Range::bytes(len - 4..=len - 1)
118+
Range::bytes(len - 4..len)
119119
.unwrap()
120120
.encode(&mut header_values);
121+
// We just pushed a header in with the `.encode` above, so there will always
122+
// be a value at `.first()`.
121123
let range_header = header_values.first().unwrap();
122124

123125
let (status, headers, mut response) = attohttpc::get(url)

crates/volta-core/src/tool/node/resolve.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ fn resolve_node_versions(url: &str) -> Fallible<RawNodeIndex> {
258258

259259
let mut header_values = Vec::with_capacity(1);
260260
expires.encode(&mut header_values);
261+
// Since we just `.encode()`d into `header_values
261262
let encoded_expires = header_values.first().unwrap().to_str().unwrap();
262263

263264
write!(expiry_file, "{}", encoded_expires).with_context(|| {

tests/acceptance/support/sandbox.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ impl CacheBuilder {
5252

5353
let mut header_values = Vec::with_capacity(1);
5454
expiry_date.encode(&mut header_values);
55+
// Since we just `.encode()`d into `header_values, it is guaranteed to
56+
// have a `.first()`.
5557
let encoded_expiry_date = header_values.first().unwrap();
5658

5759
let mut expiry_file = File::create(&self.expiry_path).unwrap_or_else(|e| {

0 commit comments

Comments
 (0)