Skip to content

Conversation

LeoSchae
Copy link
Contributor

Fix for issue #1680.

The implementation of &str::to_glib_none() copies the string and causes an error, as the item_text argument is required to be a sub sequence of paragraph_text (if paragraph_text is not null). This is no longer the case after copying both strings.

The new wrapper uses &str::as_bytes() to prevent the copy. Both pango_shape_full and pango_shape_with_flags do not rely on null terminators when passing a non-negative length as argument, so this does not cause undefined behavior.

// Using to_glib_none() on &str will copy the string and cause problems.
ffi::pango_shape_full(
item_text.to_glib_none().0,
item_text.as_bytes().to_glib_none().0 as *const c_char,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
item_text.as_bytes().to_glib_none().0 as *const c_char,
item_text.as_ptr() as *const c_char,

seems simpler. Can you update that? Otherwise seems all correct, thanks!

@sdroege sdroege added the needs-backport PR needs backporting to the current stable branch label Mar 11, 2025
@LeoSchae
Copy link
Contributor Author

I changed it to use as_ptr in all 4 cases (and made both functions use the same local variable definitions).

@sdroege sdroege merged commit 8523f56 into gtk-rs:main Mar 11, 2025
46 of 48 checks passed
@sdroege sdroege added backported PR was backported to the current stable branch and removed needs-backport PR needs backporting to the current stable branch labels May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backported PR was backported to the current stable branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants