summaryrefslogtreecommitdiff
path: root/pango/pangofc-font.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/pangofc-font.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/pangofc-font.c')
-rw-r--r--pango/pangofc-font.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index b463e90c..c35b77ee 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -588,6 +588,7 @@ pango_fc_font_get_metrics (PangoFont *font,
PangoRectangle extents;
const char *sample_str = pango_language_get_sample_string (language);
PangoFontDescription *desc = pango_font_describe_with_absolute_size (font);
+ gulong sample_str_width;
layout = pango_layout_new (context);
pango_layout_set_font_description (layout, desc);
@@ -596,7 +597,9 @@ pango_fc_font_get_metrics (PangoFont *font,
pango_layout_set_text (layout, sample_str, -1);
pango_layout_get_extents (layout, NULL, &extents);
- info->metrics->approximate_char_width = extents.width / pango_utf8_strwidth (sample_str);
+ sample_str_width = pango_utf8_strwidth (sample_str);
+ g_assert (sample_str_width > 0);
+ info->metrics->approximate_char_width = extents.width / sample_str_width;
pango_layout_set_text (layout, "0123456789", -1);
info->metrics->approximate_digit_width = max_glyph_width (layout);