Skip to content

Commit 5ab91aa

Browse files
Fix static analysis
1 parent 69ef4c2 commit 5ab91aa

File tree

8 files changed

+24
-26
lines changed

8 files changed

+24
-26
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pending_review_screen = ["ledger_device_sdk/pending_review_screen"]
2222
curve = ["secp256k1"]
2323
flags = "0"
2424
path = [""]
25-
name = "Rust Boilerplate"
2625

2726
[package.metadata.ledger.nanos]
2827
icon = "crab.gif"

src/app_ui/address.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ use ledger_device_ui_sdk::ui::{Field, MultiFieldReview};
2525
const DISPLAY_ADDR_BYTES_LEN: usize = 20;
2626

2727
pub fn ui_display_pk(addr: &[u8]) -> Result<bool, AppSW> {
28-
let addr_hex_str_buf = to_hex_all_caps(&addr[addr.len() - DISPLAY_ADDR_BYTES_LEN as usize..])
28+
let addr_hex_str_buf = to_hex_all_caps(&addr[addr.len() - DISPLAY_ADDR_BYTES_LEN..])
2929
.map_err(|_| AppSW::AddrDisplayFail)?;
3030
let addr_hex_str = from_utf8(&addr_hex_str_buf[..DISPLAY_ADDR_BYTES_LEN * 2])
3131
.map_err(|_| AppSW::AddrDisplayFail)?;
3232

3333
let mut addr_hex_str_with_prefix_buf = [0u8; DISPLAY_ADDR_BYTES_LEN * 2 + 2];
34-
concatenate(&["0x", &addr_hex_str], &mut addr_hex_str_with_prefix_buf);
34+
concatenate(&["0x", addr_hex_str], &mut addr_hex_str_with_prefix_buf);
3535
let addr_hex_str_with_prefix =
3636
from_utf8(&addr_hex_str_with_prefix_buf).map_err(|_| AppSW::AddrDisplayFail)?;
3737

src/app_ui/menu.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ fn ui_about_menu(comm: &mut Comm) -> Event<ApduHeader> {
2828
loop {
2929
match MultiPageMenu::new(comm, &pages).show() {
3030
EventOrPageIndex::Event(e) => return e,
31-
i => match i {
32-
EventOrPageIndex::Index(1) => return ui_menu_main(comm),
33-
_ => (),
34-
},
31+
i => {
32+
if let EventOrPageIndex::Index(1) = i {
33+
return ui_menu_main(comm);
34+
}
35+
}
3536
}
3637
}
3738
}

src/app_ui/sign.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ pub fn ui_display_tx(tx: &Tx) -> Result<bool, AppSW> {
3636
.trim_matches(char::from(0));
3737

3838
// Format destination address
39-
let hex_addr_buf = to_hex_all_caps(&tx.to).map_err(|_| AppSW::TxDisplayFail)?;
39+
let hex_addr_buf = to_hex_all_caps(tx.to).map_err(|_| AppSW::TxDisplayFail)?;
4040
let hex_addr_str = from_utf8(&hex_addr_buf).map_err(|_| AppSW::TxDisplayFail)?;
4141
let mut addr_with_prefix_buf = [0u8; 42];
4242
concatenate(&["0x", hex_addr_str], &mut addr_with_prefix_buf);
4343
let hex_addr_str_with_prefix =
4444
from_utf8(&addr_with_prefix_buf).map_err(|_| AppSW::TxDisplayFail)?;
4545

4646
// Format memo
47-
let memo_str = from_utf8(&tx.memo[..tx.memo_len as usize]).map_err(|_| AppSW::TxDisplayFail)?;
47+
let memo_str = from_utf8(&tx.memo[..tx.memo_len]).map_err(|_| AppSW::TxDisplayFail)?;
4848

4949
// Define transaction review fields
5050
let my_fields = [

src/handlers/get_public_key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn handler_get_public_key(comm: &mut Comm, display: bool) -> Result<(), AppS
5454
&mut keccak256.header as *mut cx_hash_t,
5555
CX_LAST,
5656
pk_ptr,
57-
64 as usize,
57+
64_usize,
5858
address.as_mut_ptr(),
5959
address.len(),
6060
) != CX_OK

src/handlers/sign_tx.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use ledger_secure_sdk_sys::{
2626
const MAX_TRANSACTION_LEN: usize = 510;
2727

2828
pub struct Tx<'a> {
29+
#[allow(dead_code)]
2930
nonce: u64,
3031
pub value: u64,
3132
pub to: &'a [u8],

src/main.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ enum Ins {
8686
GetAppName,
8787
GetPubkey,
8888
SignTx,
89-
UnknownIns,
89+
Unknown,
9090
}
9191

9292
impl From<ApduHeader> for Ins {
@@ -96,7 +96,7 @@ impl From<ApduHeader> for Ins {
9696
4 => Ins::GetAppName,
9797
5 => Ins::GetPubkey,
9898
6 => Ins::SignTx,
99-
_ => Ins::UnknownIns,
99+
_ => Ins::Unknown,
100100
}
101101
}
102102
}
@@ -107,16 +107,14 @@ extern "C" fn sample_pending() {
107107

108108
loop {
109109
ui::SingleMessage::new("Pending").show();
110-
match comm.next_event::<Ins>() {
111-
Event::Button(ButtonEvent::RightButtonRelease) => break,
112-
_ => (),
110+
if let Event::Button(ButtonEvent::RightButtonRelease) = comm.next_event::<Ins>() {
111+
break;
113112
}
114113
}
115114
loop {
116115
ui::SingleMessage::new("Ledger review").show();
117-
match comm.next_event::<Ins>() {
118-
Event::Button(ButtonEvent::BothButtonsRelease) => break,
119-
_ => (),
116+
if let Event::Button(ButtonEvent::BothButtonsRelease) = comm.next_event::<Ins>() {
117+
break;
120118
}
121119
}
122120
}
@@ -129,12 +127,11 @@ extern "C" fn sample_main() {
129127
loop {
130128
// Wait for either a specific button push to exit the app
131129
// or an APDU command
132-
match ui_menu_main(&mut comm) {
133-
Event::Command(ins) => match handle_apdu(&mut comm, ins.into(), &mut tx_ctx) {
130+
if let Event::Command(ins) = ui_menu_main(&mut comm) {
131+
match handle_apdu(&mut comm, ins.into(), &mut tx_ctx) {
134132
Ok(()) => comm.reply_ok(),
135133
Err(sw) => comm.reply(Reply::from(sw)),
136-
},
137-
_ => (),
134+
}
138135
}
139136
}
140137
}
@@ -170,7 +167,7 @@ fn handle_apdu(comm: &mut Comm, ins: Ins, ctx: &mut TxContext) -> Result<(), App
170167

171168
match comm.get_data() {
172169
Ok(data) => {
173-
if data.len() == 0 {
170+
if data.is_empty() {
174171
return Err(AppSW::WrongDataLength);
175172
}
176173
}
@@ -189,7 +186,7 @@ fn handle_apdu(comm: &mut Comm, ins: Ins, ctx: &mut TxContext) -> Result<(), App
189186

190187
match comm.get_data() {
191188
Ok(data) => {
192-
if data.len() == 0 {
189+
if data.is_empty() {
193190
return Err(AppSW::WrongDataLength);
194191
}
195192
}
@@ -203,7 +200,7 @@ fn handle_apdu(comm: &mut Comm, ins: Ins, ctx: &mut TxContext) -> Result<(), App
203200
ctx,
204201
);
205202
}
206-
Ins::UnknownIns => {
203+
Ins::Unknown => {
207204
return Err(AppSW::InsNotSupported);
208205
}
209206
}

src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn to_hex_all_caps(m: &[u8]) -> Result<[u8; MAX_HEX_LEN], ()> {
4040
/// Convert serialized derivation path to u32 array elements
4141
pub fn read_bip32_path(data: &[u8], path: &mut [u32]) -> Result<usize, AppSW> {
4242
// Check input length and path buffer capacity
43-
if data.len() < 1 || path.len() < data.len() / 4 {
43+
if data.is_empty() || path.len() < data.len() / 4 {
4444
return Err(AppSW::WrongDataLength);
4545
}
4646

0 commit comments

Comments
 (0)