Skip to content

Commit

Permalink
native-activity: Check for null saved_state_in pointer
Browse files Browse the repository at this point in the history
Avoids calling `std::slice::from_raw_parts` with a null `saved_state_in`
pointer.

Fixes: #153
  • Loading branch information
skibon02 authored and rib committed Apr 26, 2024
1 parent 6a0197c commit 7bd3ba6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions android-activity/src/native_activity/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,12 @@ impl WaitableNativeActivityState {
}
}

let saved_state =
unsafe { std::slice::from_raw_parts(saved_state_in as *const u8, saved_state_size) };
let saved_state = if saved_state_in.is_null() {
Vec::new()
} else {
unsafe { std::slice::from_raw_parts(saved_state_in as *const u8, saved_state_size) }
.to_vec()
};

let config = unsafe {
let config = ndk_sys::AConfiguration_new();
Expand All @@ -357,7 +361,7 @@ impl WaitableNativeActivityState {
msg_read: msgpipe[0],
msg_write: msgpipe[1],
config,
saved_state: saved_state.into(),
saved_state,
input_queue: ptr::null_mut(),
window: None,
content_rect: Rect::empty().into(),
Expand Down

0 comments on commit 7bd3ba6

Please sign in to comment.