Skip to content

Commit

Permalink
Fix use after free in show_message_box
Browse files Browse the repository at this point in the history
Fixes #1305.
  • Loading branch information
n1000 committed Feb 9, 2024
1 parent c971a98 commit 65b8914
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/sdl2/messagebox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,20 @@ where
})
.collect();
let result = unsafe {
let scheme = scheme.map(|scheme| sys::SDL_MessageBoxColorScheme {
colors: scheme.into(),
});
let msg_box_data = sys::SDL_MessageBoxData {
flags: flags.bits(),
window: window.map_or(ptr::null_mut(), |win| win.raw()),
title: title.as_ptr() as *const c_char,
message: message.as_ptr() as *const c_char,
numbuttons: raw_buttons.len() as c_int,
buttons: raw_buttons.as_ptr(),
colorScheme: if let Some(scheme) = scheme {
&sys::SDL_MessageBoxColorScheme {
colors: From::from(scheme),
} as *const _
} else {
ptr::null()
},
colorScheme: scheme
.as_ref()
.map(|p| p as *const _)
.unwrap_or(ptr::null()),
};
sys::SDL_ShowMessageBox(&msg_box_data as *const _, &mut button_id as &mut _)
} == 0;
Expand Down

0 comments on commit 65b8914

Please sign in to comment.