diff --git a/generator/src/main.rs b/generator/src/main.rs index a525c12c..ec3c689a 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -1495,6 +1495,7 @@ impl Parser { #![allow(clippy::wrong_self_convention, clippy::transmute_ptr_to_ptr)] use std::borrow::Cow; + use std::ffi::CStr; use std::mem::MaybeUninit; pub use sys::{#(#reexports),*}; pub use sys::platform::{EGLenum, VkFilter, VkSamplerMipmapMode, VkSamplerAddressMode, VkComponentSwizzle}; @@ -1517,9 +1518,13 @@ impl Parser { match crate::fixed_str_bytes(&ext.extension_name) { #(#ext_set_inits)* bytes => { - if let Ok(name) = std::str::from_utf8(bytes) { - out.other.push(name.into()); - } + let cstr = CStr::from_bytes_with_nul(bytes) + .expect("extension names should be null terminated strings"); + let string = cstr + .to_str() + .expect("extension names should be valid UTF-8") + .to_string(); + out.other.push(string); } } } diff --git a/openxr/src/generated.rs b/openxr/src/generated.rs index 8b9ee106..c15e6d0b 100644 --- a/openxr/src/generated.rs +++ b/openxr/src/generated.rs @@ -2,6 +2,7 @@ #![allow(clippy::wrong_self_convention, clippy::transmute_ptr_to_ptr)] use crate::*; use std::borrow::Cow; +use std::ffi::CStr; use std::mem::MaybeUninit; pub use sys::platform::{ EGLenum, VkComponentSwizzle, VkFilter, VkSamplerAddressMode, VkSamplerMipmapMode, @@ -686,9 +687,13 @@ impl ExtensionSet { out.htcx_vive_tracker_interaction = true; } bytes => { - if let Ok(name) = std::str::from_utf8(bytes) { - out.other.push(name.into()); - } + let cstr = CStr::from_bytes_with_nul(bytes) + .expect("extension names should be null terminated strings"); + let string = cstr + .to_str() + .expect("extension names should be valid UTF-8") + .to_string(); + out.other.push(string); } } }