Skip to content

Fix bug in bindings of pango::shape_full and pango::shape_with_flags #1681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 11, 2025

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.

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