add null-check for empty arrays in debug trampoline (#2490)

This commit is contained in:
Aspen 2024-03-06 15:32:44 -08:00 committed by GitHub
parent b9f1cc3b7c
commit 12c3c9dd26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -340,13 +340,29 @@ pub(super) unsafe extern "system" fn trampoline(
message_id_number,
message: CStr::from_ptr(p_message).to_str().unwrap(),
queue_labels: DebugUtilsMessengerCallbackLabelIter(
slice::from_raw_parts(p_queue_labels, queue_label_count as usize).iter(),
// Some drivers give a null pointer for empty data.
if p_queue_labels.is_null() {
&[]
} else {
slice::from_raw_parts(p_queue_labels, queue_label_count as usize)
}
.iter(),
),
cmd_buf_labels: DebugUtilsMessengerCallbackLabelIter(
slice::from_raw_parts(p_cmd_buf_labels, cmd_buf_label_count as usize).iter(),
if p_cmd_buf_labels.is_null() {
&[]
} else {
slice::from_raw_parts(p_cmd_buf_labels, cmd_buf_label_count as usize)
}
.iter(),
),
objects: DebugUtilsMessengerCallbackObjectNameInfoIter(
slice::from_raw_parts(p_objects, object_count as usize).iter(),
if p_objects.is_null() {
&[]
} else {
slice::from_raw_parts(p_objects, object_count as usize)
}
.iter(),
),
};