diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2009-07-15 13:59:20 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2009-07-15 14:00:31 -0400 |
commit | 67052645e6afcd7f72ef852c99ee88897d2022da (patch) | |
tree | 90ae6efbad01f32febc2fea57c8b1dd1005a6fdc /pango/pango-impl-utils.h | |
parent | 4d6f980b9f67e7e969e6f5afeb6f216c0a99e6f4 (diff) | |
download | pango-67052645e6afcd7f72ef852c99ee88897d2022da.tar.gz |
Handle NUL in text in places that g_utf8_strlen () was used
While pango-layout doesn't allow NUL in text, the lower level API should
handle it correctly. We were using g_utf8_strlen() in a number of
places. This is problematic since that function stops processing at
NUL even if length>1. We now use an internal pango_utf8_strlen() instead.
Inspired by:
Bug 588678 – pango crash: install a new theme from gnome-appearance-properties
Diffstat (limited to 'pango/pango-impl-utils.h')
-rw-r--r-- | pango/pango-impl-utils.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/pango/pango-impl-utils.h b/pango/pango-impl-utils.h index a04d4241..3ef3a0c4 100644 --- a/pango/pango-impl-utils.h +++ b/pango/pango-impl-utils.h @@ -122,6 +122,33 @@ pango_utf8_strwidth (const gchar *p) return len; } +/* Glib's g_utf8_strlen() is broken and stops at embedded NUL's. + * Wrap it here. */ +static G_GNUC_UNUSED glong +pango_utf8_strlen (const gchar *p, gssize max) +{ + glong len = 0; + const gchar *start = p; + g_return_val_if_fail (p != NULL || max == 0, 0); + + if (max <= 0) + return g_utf8_strlen (p, max); + + p = g_utf8_next_char (p); + while (p - start < max) + { + ++len; + p = g_utf8_next_char (p); + } + + /* only do the last len increment if we got a complete + * char (don't count partial chars) + */ + if (p - start <= max) + ++len; + + return len; +} G_END_DECLS |