summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-08-08 08:31:43 -0700
committerMatthias Clasen <mclasen@redhat.com>2019-08-08 08:31:43 -0700
commit36a55406a86ceee67ee720bc81eb4c7c00fce267 (patch)
tree7ff153cc0b990018e6d1e7d56ae96b151e4abc3c
parent6968eaf07afebc2cb6690183ca0528303609def2 (diff)
downloadpango-36a55406a86ceee67ee720bc81eb4c7c00fce267.tar.gz
Prevent a crash in ellipsization
We were crashing when ellipsizing text without any attributes. Test included.
-rw-r--r--pango/ellipsize.c6
-rw-r--r--tests/test-ellipsize.c32
2 files changed, 32 insertions, 6 deletions
diff --git a/pango/ellipsize.c b/pango/ellipsize.c
index 002853c3..304d89fc 100644
--- a/pango/ellipsize.c
+++ b/pango/ellipsize.c
@@ -119,7 +119,10 @@ init_state (EllipsizeState *state,
int start_offset;
state->layout = line->layout;
- state->attrs = attrs;
+ if (attrs)
+ state->attrs = pango_attr_list_ref (attrs);
+ else
+ state->attrs = pango_attr_list_new ();
state->n_runs = g_slist_length (line->runs);
state->run_info = g_new (RunInfo, state->n_runs);
@@ -151,6 +154,7 @@ init_state (EllipsizeState *state,
static void
free_state (EllipsizeState *state)
{
+ pango_attr_list_unref (state->attrs);
if (state->line_start_attr)
pango_attr_iterator_destroy (state->line_start_attr);
if (state->gap_start_attr)
diff --git a/tests/test-ellipsize.c b/tests/test-ellipsize.c
index 1c262aa1..20819d0b 100644
--- a/tests/test-ellipsize.c
+++ b/tests/test-ellipsize.c
@@ -25,11 +25,11 @@
static PangoContext *context;
-/* Test that ellipsization does not change the
- * height of a layout.
+/* Test that ellipsization does not change the height of a layout.
+ * See https://gitlab.gnome.org/GNOME/pango/issues/397
*/
static void
-test_ellipsize (void)
+test_ellipsize_height (void)
{
PangoLayout *layout;
int height1, height2;
@@ -38,7 +38,7 @@ test_ellipsize (void)
layout = pango_layout_new (context);
desc = pango_font_description_from_string ("Fixed 7");
- pango_layout_set_font_description (layout, desc);
+ //pango_layout_set_font_description (layout, desc);
pango_font_description_free (desc);
pango_layout_set_text (layout, "some text that should be ellipsized", -1);
@@ -57,6 +57,27 @@ test_ellipsize (void)
g_object_unref (layout);
}
+/* Test that ellipsization without attributes does not crash
+ */
+static void
+test_ellipsize_crash (void)
+{
+ PangoLayout *layout;
+
+ layout = pango_layout_new (context);
+
+ pango_layout_set_text (layout, "some text that should be ellipsized", -1);
+ g_assert_cmpint (pango_layout_get_line_count (layout), ==, 1);
+
+ pango_layout_set_width (layout, 100 * PANGO_SCALE);
+ pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
+
+ g_assert_cmpint (pango_layout_get_line_count (layout), ==, 1);
+ g_assert_cmpint (pango_layout_is_ellipsized (layout), ==, 1);
+
+ g_object_unref (layout);
+}
+
int
main (int argc, char *argv[])
{
@@ -67,7 +88,8 @@ main (int argc, char *argv[])
g_test_init (&argc, &argv, NULL);
- g_test_add_func ("/layout/ellipsize", test_ellipsize);
+ g_test_add_func ("/layout/ellipsize/height", test_ellipsize_height);
+ g_test_add_func ("/layout/ellipsize/crash", test_ellipsize_crash);
return g_test_run ();
}