GNOME Bugzilla – Bug 779456
Make g_utf8_make_valid optionally take a length
Last modified: 2017-03-02 11:30:12 UTC
g_utf8_make_valid was turned into a public API this cycle. However now that it is public we should make the API more generic, allowing the caller to specify the length. This is especially useful if the function is called with a string that has \0 in the middle or for chunks of a strings that are not nul terminated. This is also consistent with most of the other utf8 utils. Callers inside glib are updated to the new signature.
Created attachment 347033 [details] [review] proof of concept patch I quickly threw together a patch since we are so close to the freeze, however I do not have a building checkout right here, so it is not tested
I checked it builds and make check passes.
Review of attachment 347033 [details] [review]: > g_utf8_make_valid optionally take a length Seems like the commit subject is missing a verb like ‘Make …’. ::: glib/gutf8.c @@ +1771,3 @@ string = NULL; remainder = str; + remaining_bytes = len; If you’re going to make @len a gssize (which is correct), I think @remaining_bytes and @valid_bytes need to be gsize.
Created attachment 347040 [details] [review] Make g_utf8_make_valid optionally take a length g_utf8_make_valid was turned into a public API this cycle. However now that it is public we should make the API more generic, allowing the caller to specify the length. This is especially useful if the function is called with a string that has \0 in the middle or for chunks of a strings that are not nul terminated. This is also consistent with most of the other utf8 utils. Callers inside glib are updated to the new signature.
Review of attachment 347040 [details] [review]: Looks good to me. Needs to be acked by a GLib maintainer though.
Ideally, we'd have done this before landing it. But better now than never. I'm ok with landing this.
Review of attachment 347040 [details] [review]: ok then
Attachment 347040 [details] pushed as f559bc0 - Make g_utf8_make_valid optionally take a length