Skip to content

Commit

Permalink
Use ArrayVec::push_many_from_slice to make code safer
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ericson2314 committed Apr 11, 2023
1 parent deba3f7 commit 4316f27
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Expand Up @@ -13,6 +13,9 @@ nanos_sdk = { git = "https://github.com/LedgerHQ/ledger-nanos-sdk.git" }
nanos_ui = { git = "https://github.com/LedgerHQ/ledger-nanos-ui.git" }
ledger-parser-combinators = { git = "https://github.com/alamgu/ledger-parser-combinators", branch="async-split-take-2" }

[patch."crates-io".arrayvec]
git = "https://github.com/obsidiansystems/arrayvec"
branch = "push-many-from-slice"
[patch."https://github.com/LedgerHQ/ledger-nanos-sdk.git".nanos_sdk]
git = "https://github.com/alamgu/ledger-nanos-sdk.git"
branch = "relocating-loader-w-fixes"
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Expand Up @@ -425,8 +425,8 @@ impl Readable for ByteStream {
while !buffer.is_full() {
let block = self.get_current_block().await;
let avail = self.slice_from_block(&block);
let consuming = core::cmp::min(avail.len(), buffer.remaining_capacity());
buffer.try_extend_from_slice(&avail[0..consuming]).ok();
let remaining = buffer.push_many_from_slice(&avail).len();
let consuming = avail.len() - remaining;
self.consume(&*block, consuming);
}
buffer.into_inner().unwrap()
Expand Down

0 comments on commit 4316f27

Please sign in to comment.