diff options
author | Philip Withnall <withnall@endlessm.com> | 2017-02-14 11:12:51 +0000 |
---|---|---|
committer | Philip Withnall <withnall@endlessm.com> | 2017-02-14 11:16:05 +0000 |
commit | e4ea2d2e5118b44bf1c3e5fa998356696e073aa8 (patch) | |
tree | 90682d671f6b83bd4d274653fe46565eac75bd34 /pango/pangocairo-font.c | |
parent | 318fd546a0ab8ad68f65f5f81b0a6fb845141a9f (diff) | |
download | pango-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/pangocairo-font.c')
-rw-r--r-- | pango/pangocairo-font.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c index 97df00c5..b86f85b7 100644 --- a/pango/pangocairo-font.c +++ b/pango/pangocairo-font.c @@ -249,6 +249,7 @@ _pango_cairo_font_get_metrics (PangoFont *font, cairo_matrix_t cairo_matrix; PangoMatrix pango_matrix; PangoMatrix identity = PANGO_MATRIX_INIT; + glong sample_str_width; int height, shift; @@ -311,7 +312,9 @@ _pango_cairo_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); |