Skip to content

Commit e283074

Browse files
committed
bitbox02/ui/menu: avoid premature drop of title
Without the use of `as_ref()`, the contents of the Option is moved into the callback and dropped on return, creating a dangling pointer.
1 parent b815597 commit e283074

File tree

1 file changed

+4
-2
lines changed
  • src/rust/bitbox02/src/ui

1 file changed

+4
-2
lines changed

src/rust/bitbox02/src/ui/ui.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,17 @@ pub fn menu_create(params: MenuParams<'_>) -> Component<'_> {
279279
};
280280
let title = params
281281
.title
282-
.map(|title| crate::str_to_cstr_force!(title, MAX_LABEL_SIZE));
282+
.map(|title| crate::util::str_to_cstr_vec(title).unwrap());
283283
let component = unsafe {
284284
bitbox02_sys::menu_create(
285285
c_words.as_ptr(),
286286
select_word_cb,
287287
select_word_cb_param,
288288
words.len() as _,
289289
// copied in C
290-
title.map_or_else(|| core::ptr::null(), |title| title.as_ptr()),
290+
title
291+
.as_ref()
292+
.map_or_else(|| core::ptr::null(), |title| title.as_ptr()),
291293
continue_on_last_cb,
292294
continue_on_last_cb_param,
293295
cancel_cb,

0 commit comments

Comments
 (0)