Skip to content

Commit

Permalink
Remove null terminators from "other" extension names
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmusgo authored May 19, 2024
1 parent d7322e1 commit 155efe0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 8 additions & 3 deletions generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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);
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions openxr/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 155efe0

Please sign in to comment.