From 739549eb7b4374253b6d529695e07cdd6445644e Mon Sep 17 00:00:00 2001 From: Patrick Owen Date: Fri, 3 May 2024 18:46:16 -0400 Subject: [PATCH] Handle null ptr in fmt_labels --- client/src/graphics/core.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/src/graphics/core.rs b/client/src/graphics/core.rs index 252ad7f8..377a35ed 100644 --- a/client/src/graphics/core.rs +++ b/client/src/graphics/core.rs @@ -130,6 +130,12 @@ unsafe extern "system" fn messenger_callback( _p_user_data: *mut c_void, ) -> vk::Bool32 { unsafe fn fmt_labels(ptr: *const vk::DebugUtilsLabelEXT, count: u32) -> String { + if count == 0 { + // We need to handle a count of 0 separately because ptr may be + // null, resulting in undefined behavior if used with + // slice::from_raw_parts. + return String::new(); + } slice::from_raw_parts(ptr, count as usize) .iter() .map(|label| {