mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 14:55:05 +00:00
Ensure DeviceLostClosureC callbacks have null-terminated message strings. (#4744)
This commit is contained in:
parent
30d67a329a
commit
877dd5b26c
@ -273,19 +273,15 @@ impl DeviceLostClosure {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(trivial_casts)]
|
|
||||||
pub(crate) fn call(self, reason: DeviceLostReason, message: String) {
|
pub(crate) fn call(self, reason: DeviceLostReason, message: String) {
|
||||||
match self.inner {
|
match self.inner {
|
||||||
DeviceLostClosureInner::Rust { callback } => callback(reason, message),
|
DeviceLostClosureInner::Rust { callback } => callback(reason, message),
|
||||||
// SAFETY: the contract of the call to from_c says that this unsafe is sound.
|
// SAFETY: the contract of the call to from_c says that this unsafe is sound.
|
||||||
DeviceLostClosureInner::C { inner } => unsafe {
|
DeviceLostClosureInner::C { inner } => unsafe {
|
||||||
// We need to pass message as a c_char typed pointer. To avoid trivial
|
// Ensure message is structured as a null-terminated C string. It only
|
||||||
// conversion warnings on some platforms, we use the allow lint.
|
// needs to live as long as the callback invocation.
|
||||||
(inner.callback)(
|
let message = std::ffi::CString::new(message).unwrap();
|
||||||
inner.user_data,
|
(inner.callback)(inner.user_data, reason as u8, message.as_ptr())
|
||||||
reason as u8,
|
|
||||||
message.as_ptr() as *const c_char,
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user