Skip to content

Commit d8fa38c

Browse files
committed
Use ArrayVec::push_many_from_slice to make code safer
We were ignoring potential (even though it shouldn't happen) failure. The new way however is correct by construction. The `ArrayVec` method is from bluss/arrayvec#237
1 parent 56c1e97 commit d8fa38c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ nanos_sdk = { git = "https://github.com/LedgerHQ/ledger-nanos-sdk.git" }
1313
nanos_ui = { git = "https://github.com/LedgerHQ/ledger-nanos-ui.git" }
1414
ledger-parser-combinators = { git = "https://github.com/alamgu/ledger-parser-combinators", branch="async-split-take-2" }
1515

16+
[patch."crates-io".arrayvec]
17+
git = "https://github.com/obsidiansystems/arrayvec"
18+
branch = "push-many-from-slice"
1619
[patch."https://github.com/LedgerHQ/ledger-nanos-sdk.git".nanos_sdk]
1720
git = "https://github.com/alamgu/ledger-nanos-sdk.git"
1821
branch = "relocating-loader-w-fixes"

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ impl Readable for ByteStream {
363363
Err(_) => reject().await,
364364
};
365365
let avail = &chunk[self.current_offset + HASH_LEN..];
366-
let consuming = core::cmp::min(avail.len(), buffer.remaining_capacity());
367-
buffer.try_extend_from_slice(&avail[0..consuming]).ok();
366+
let remaining = buffer.push_many_from_slice(&avail).len();
367+
let consuming = avail.len() - remaining;
368368
self.current_offset += consuming;
369369
if self.current_offset + HASH_LEN == chunk.len() {
370370
self.current_chunk = chunk[0..HASH_LEN].try_into().unwrap();

0 commit comments

Comments
 (0)