Skip to content

Commit 7bd3ba6

Browse files
skibon02rib
authored andcommitted
native-activity: Check for null saved_state_in pointer
Avoids calling `std::slice::from_raw_parts` with a null `saved_state_in` pointer. Fixes: #153
1 parent 6a0197c commit 7bd3ba6

File tree

1 file changed

+7
-3
lines changed
  • android-activity/src/native_activity

1 file changed

+7
-3
lines changed

android-activity/src/native_activity/glue.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,12 @@ impl WaitableNativeActivityState {
337337
}
338338
}
339339

340-
let saved_state =
341-
unsafe { std::slice::from_raw_parts(saved_state_in as *const u8, saved_state_size) };
340+
let saved_state = if saved_state_in.is_null() {
341+
Vec::new()
342+
} else {
343+
unsafe { std::slice::from_raw_parts(saved_state_in as *const u8, saved_state_size) }
344+
.to_vec()
345+
};
342346

343347
let config = unsafe {
344348
let config = ndk_sys::AConfiguration_new();
@@ -357,7 +361,7 @@ impl WaitableNativeActivityState {
357361
msg_read: msgpipe[0],
358362
msg_write: msgpipe[1],
359363
config,
360-
saved_state: saved_state.into(),
364+
saved_state,
361365
input_queue: ptr::null_mut(),
362366
window: None,
363367
content_rect: Rect::empty().into(),

0 commit comments

Comments
 (0)