Skip to content

Commit 4316f27

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 deba3f7 commit 4316f27

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
@@ -425,8 +425,8 @@ impl Readable for ByteStream {
425425
while !buffer.is_full() {
426426
let block = self.get_current_block().await;
427427
let avail = self.slice_from_block(&block);
428-
let consuming = core::cmp::min(avail.len(), buffer.remaining_capacity());
429-
buffer.try_extend_from_slice(&avail[0..consuming]).ok();
428+
let remaining = buffer.push_many_from_slice(&avail).len();
429+
let consuming = avail.len() - remaining;
430430
self.consume(&*block, consuming);
431431
}
432432
buffer.into_inner().unwrap()

0 commit comments

Comments
 (0)