summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-05-23 16:47:30 +0000
committerMatthias Clasen <mclasen@redhat.com>2021-05-23 16:47:30 +0000
commit3276a33b1ef9db42d46bf649d693016c4587f368 (patch)
tree4ff0402df2dcf9f3a982101d3971304bc46deb68
parent27b4ae6596c3d4ef6d11baff78300c18331f6349 (diff)
parentdad38adf4e8a7ca6fbbe09d8eba0c25aa0a393d4 (diff)
downloadpango-3276a33b1ef9db42d46bf649d693016c4587f368.tar.gz
Merge branch 'fix-attr-list-update' into 'master'
Avoid unsigned int pitfalls Closes #561 See merge request GNOME/pango!336
-rw-r--r--pango/pango-attributes.c3
-rw-r--r--tests/testmisc.c26
2 files changed, 28 insertions, 1 deletions
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index 63c031f9..f97892a6 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -1777,7 +1777,8 @@ pango_attr_list_update (PangoAttrList *list,
}
else if (attr->end_index >= pos + remove)
{
- if (G_MAXUINT - attr->end_index < add - remove)
+ if (add > remove &&
+ G_MAXUINT - attr->end_index < add - remove)
attr->end_index = G_MAXUINT;
else
attr->end_index += add - remove;
diff --git a/tests/testmisc.c b/tests/testmisc.c
index 06b39a7a..0767eb7a 100644
--- a/tests/testmisc.c
+++ b/tests/testmisc.c
@@ -121,6 +121,31 @@ test_line_height (void)
g_object_unref (context);
}
+static void
+test_attr_list_update (void)
+{
+ PangoAttribute *weight_attr;
+ PangoAttrList *list;
+
+ weight_attr = pango_attr_weight_new (700);
+ weight_attr->start_index = 4;
+ weight_attr->end_index = 6;
+
+ list = pango_attr_list_new();
+ pango_attr_list_insert (list, weight_attr);
+
+ g_assert_cmpuint (weight_attr->start_index, ==, 4);
+ g_assert_cmpuint (weight_attr->end_index, ==, 6);
+
+ // Delete 1 byte at position 2
+ pango_attr_list_update (list, 2, 1, 0);
+
+ g_assert_cmpuint (weight_attr->start_index, ==, 3);
+ g_assert_cmpuint (weight_attr->end_index, ==, 5);
+
+ pango_attr_list_unref (list);
+}
+
int
main (int argc, char *argv[])
{
@@ -132,6 +157,7 @@ main (int argc, char *argv[])
g_test_add_func ("/layout/short-string-crash", test_short_string_crash);
g_test_add_func ("/language/emoji-crash", test_language_emoji_crash);
g_test_add_func ("/layout/line-height", test_line_height);
+ g_test_add_func ("/attr-list/update", test_attr_list_update);
return g_test_run ();
}