Skip to content

Commit 647c411

Browse files
authored
Null-check hb_language_t before CStr::from_ptr (#273)
1 parent d7e3737 commit 647c411

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

harfbuzz/src/language.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ impl Language {
6868
/// assert_eq!(lang.to_string(), "en-us");
6969
/// ```
7070
pub fn to_string(&self) -> &str {
71+
// Since we panic if we have a non-UTF-8 language tag,
72+
// we might as well panic on an invalid language tag,
73+
// which is possible if allocation failed within HarfBuzz
74+
// itself.
75+
assert!(self.is_valid());
7176
unsafe { core::ffi::CStr::from_ptr(sys::hb_language_to_string(self.raw)) }
7277
.to_str()
7378
.unwrap()

0 commit comments

Comments
 (0)