Skip to content

Commit 8b1a3fc

Browse files
committed
Test if CString is empty before calling C API
1 parent 1bc15fd commit 8b1a3fc

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

ledger_device_sdk/src/nbgl/nbgl_address_review.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl SyncNBGL for NbglAddressReview<'_> {}
1212
impl<'a> NbglAddressReview<'a> {
1313
pub fn new() -> NbglAddressReview<'a> {
1414
NbglAddressReview {
15-
verify_str: CString::new("").unwrap(),
15+
verify_str: CString::default(),
1616
glyph: None,
1717
}
1818
}
@@ -45,7 +45,10 @@ impl<'a> NbglAddressReview<'a> {
4545
address.as_ptr(),
4646
core::ptr::null(),
4747
&icon as *const nbgl_icon_details_t,
48-
self.verify_str.as_ptr(),
48+
match self.verify_str.is_empty() {
49+
true => core::ptr::null(),
50+
false => self.verify_str.as_ptr()
51+
},
4952
core::ptr::null(),
5053
Some(choice_callback),
5154
);

ledger_device_sdk/src/nbgl/nbgl_review.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ impl SyncNBGL for NbglReview<'_> {}
1717
impl<'a> NbglReview<'a> {
1818
pub fn new() -> NbglReview<'a> {
1919
NbglReview {
20-
title: CString::new("").unwrap(),
21-
subtitle: CString::new("").unwrap(),
22-
finish_title: CString::new("").unwrap(),
20+
title: CString::default(),
21+
subtitle: CString::default(),
22+
finish_title: CString::default(),
2323
glyph: None,
2424
tx_type: TransactionType::Transaction,
2525
blind: false,
@@ -130,9 +130,18 @@ impl<'a> NbglReview<'a> {
130130
self.tx_type.to_c_type(false),
131131
&tag_value_list as *const nbgl_contentTagValueList_t,
132132
&icon as *const nbgl_icon_details_t,
133-
self.title.as_ptr() as *const c_char,
134-
self.subtitle.as_ptr() as *const c_char,
135-
self.finish_title.as_ptr() as *const c_char,
133+
match self.title.is_empty() {
134+
true => core::ptr::null(),
135+
false => self.title.as_ptr() as *const c_char
136+
},
137+
match self.subtitle.is_empty() {
138+
true => core::ptr::null(),
139+
false => self.subtitle.as_ptr() as *const c_char
140+
},
141+
match self.finish_title.is_empty() {
142+
true => core::ptr::null(),
143+
false => self.finish_title.as_ptr() as *const c_char
144+
},
136145
Some(choice_callback),
137146
);
138147
}

0 commit comments

Comments
 (0)