Skip to content

Commit 6d06e63

Browse files
committed
Fix bug in bindings of shape_full and shape_with_flags
1 parent a6810cb commit 6d06e63

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

pango/src/functions.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

33
use glib::translate::*;
4+
use std::ffi::c_char;
45

56
pub use crate::auto::functions::*;
67
#[cfg(feature = "v1_44")]
@@ -27,13 +28,15 @@ pub fn shape_full(
2728
Some(s) => s.len(),
2829
None => 0,
2930
} as i32;
30-
let paragraph_text = paragraph_text.to_glib_none();
3131
let item_length = item_text.len() as i32;
3232
unsafe {
33+
// The function does not take null-terminated strings when a length is provided.
34+
// It also requires item_text to point to a subsequence of paragraph_text.
35+
// Using to_glib_none() on &str will copy the string and cause problems.
3336
ffi::pango_shape_full(
34-
item_text.to_glib_none().0,
37+
item_text.as_bytes().to_glib_none().0 as *const c_char,
3538
item_length,
36-
paragraph_text.0,
39+
paragraph_text.map(|t| t.as_bytes()).to_glib_none().0 as *const c_char,
3740
paragraph_length,
3841
analysis.to_glib_none().0,
3942
glyphs.to_glib_none_mut().0,
@@ -54,10 +57,11 @@ pub fn shape_with_flags(
5457
let item_length = item_text.len() as i32;
5558
let paragraph_length = paragraph_text.map(|t| t.len() as i32).unwrap_or_default();
5659
unsafe {
60+
// See: shape_full
5761
ffi::pango_shape_with_flags(
58-
item_text.to_glib_none().0,
62+
item_text.as_bytes().to_glib_none().0 as *const c_char,
5963
item_length,
60-
paragraph_text.to_glib_none().0,
64+
paragraph_text.map(|t| t.as_bytes()).to_glib_none().0 as *const c_char,
6165
paragraph_length,
6266
analysis.to_glib_none().0,
6367
glyphs.to_glib_none_mut().0,

0 commit comments

Comments
 (0)