From d4ad0ea8b0fcfe6007940ebd2977cefb471cb6c7 Mon Sep 17 00:00:00 2001 From: Fenrir Date: Wed, 21 Feb 2024 14:30:43 -0700 Subject: [PATCH] Move swkbd_message_callback sanity checks to the top of the fn It's kinda pointless to have those checks *after* attempting to deref the data rather than before. --- ctru-rs/src/applets/swkbd.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ctru-rs/src/applets/swkbd.rs b/ctru-rs/src/applets/swkbd.rs index 667a459..69b6f98 100644 --- a/ctru-rs/src/applets/swkbd.rs +++ b/ctru-rs/src/applets/swkbd.rs @@ -211,6 +211,7 @@ bitflags! { } // Internal book-keeping struct used to send data to `aptSetMessageCallback` when calling the software keyboard. +#[derive(Copy, Clone)] struct MessageCallbackData { filter_callback: *const Box, swkbd_shared_mem_ptr: *mut libc::c_void, @@ -802,15 +803,15 @@ impl SoftwareKeyboard { msg: *mut libc::c_void, msg_size: libc::size_t, ) { - let data = unsafe { &mut *user.cast::() }; - let swkbd = unsafe { &mut *msg.cast::() }; - if sender != ctru_sys::APPID_SOFTWARE_KEYBOARD || msg_size != std::mem::size_of::() { return; } + let swkbd = unsafe { &mut *msg.cast::() }; + let data = unsafe { *user.cast::() }; + let text16 = unsafe { widestring::Utf16Str::from_slice_unchecked(std::slice::from_raw_parts( data.swkbd_shared_mem_ptr.add(swkbd.text_offset as _).cast(),