summaryrefslogtreecommitdiff
path: root/pango/pango-context.c
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2017-02-14 11:12:51 +0000
committerPhilip Withnall <withnall@endlessm.com>2017-02-14 11:16:05 +0000
commite4ea2d2e5118b44bf1c3e5fa998356696e073aa8 (patch)
tree90682d671f6b83bd4d274653fe46565eac75bd34 /pango/pango-context.c
parent318fd546a0ab8ad68f65f5f81b0a6fb845141a9f (diff)
downloadpango-e4ea2d2e5118b44bf1c3e5fa998356696e073aa8.tar.gz
Add assertions to guard against division by zero on sample text paths
There are a few code paths where pango_utf8_strwidth() is called on language-specific sample text. The sample text should have been chosen to never have a zero width, but we should add some assertions to ensure that’s the case. This guides static analysers into the right analysis. Coverity IDs: 1391697, 1391698, 1391699 Signed-off-by: Philip Withnall <withnall@endlessm.com> https://bugzilla.gnome.org/show_bug.cgi?id=778602
Diffstat (limited to 'pango/pango-context.c')
-rw-r--r--pango/pango-context.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/pango/pango-context.c b/pango/pango-context.c
index f91d0fe6..f0cea733 100644
--- a/pango/pango-context.c
+++ b/pango/pango-context.c
@@ -1635,6 +1635,10 @@ update_metrics_from_items (PangoFontMetrics *metrics,
GHashTable *fonts_seen = g_hash_table_new (NULL, NULL);
PangoGlyphString *glyphs = pango_glyph_string_new ();
GList *l;
+ glong text_width;
+
+ /* This should typically be called with a sample text string. */
+ g_return_if_fail (text_len > 0);
metrics->approximate_char_width = 0;
@@ -1663,7 +1667,9 @@ update_metrics_from_items (PangoFontMetrics *metrics,
pango_glyph_string_free (glyphs);
g_hash_table_destroy (fonts_seen);
- metrics->approximate_char_width /= pango_utf8_strwidth (text);
+ text_width = pango_utf8_strwidth (text);
+ g_assert (text_width > 0);
+ metrics->approximate_char_width /= text_width;
}
/**