[gtk/wip/otte/filterlistmodel: 11/13] bitset: Don't overflow when splicing
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/filterlistmodel: 11/13] bitset: Don't overflow when splicing
- Date: Mon, 6 Jul 2020 01:44:51 +0000 (UTC)
commit 3d931b4fe26e7f39470b370bef4fd3710421cc06
Author: Benjamin Otte <otte redhat com>
Date: Mon Jul 6 03:35:17 2020 +0200
bitset: Don't overflow when splicing
Testcase added.
gtk/gtkbitset.c | 2 +-
testsuite/gtk/bitset.c | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkbitset.c b/gtk/gtkbitset.c
index 27cdf1ba63..1ee80500c9 100644
--- a/gtk/gtkbitset.c
+++ b/gtk/gtkbitset.c
@@ -742,7 +742,7 @@ gtk_bitset_slice (GtkBitset *self,
GtkBitset *shift = gtk_bitset_copy (self);
gtk_bitset_remove_range (shift, 0, position);
- gtk_bitset_remove_range (self, position, G_MAXUINT - position + 1);
+ gtk_bitset_remove_range_closed (self, position, G_MAXUINT);
if (added > removed)
gtk_bitset_shift_right (shift, added - removed);
else
diff --git a/testsuite/gtk/bitset.c b/testsuite/gtk/bitset.c
index e5e641a17b..8a84648324 100644
--- a/testsuite/gtk/bitset.c
+++ b/testsuite/gtk/bitset.c
@@ -543,6 +543,18 @@ test_iter (void)
gtk_bitset_unref (set);
}
+static void
+test_splice_overflow (void)
+{
+ GtkBitset *set, *compare;
+
+ set = gtk_bitset_new_range (3, 1);
+ gtk_bitset_slice (set, 0, 0, 13);
+
+ compare = gtk_bitset_new_range (16, 1);
+ g_assert_true (gtk_bitset_equals (set, compare));
+}
+
int
main (int argc, char *argv[])
{
@@ -562,6 +574,7 @@ main (int argc, char *argv[])
g_test_add_func ("/bitset/slice", test_slice);
g_test_add_func ("/bitset/rectangle", test_rectangle);
g_test_add_func ("/bitset/iter", test_iter);
+ g_test_add_func ("/bitset/splice-overflow", test_splice_overflow);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]