bitset: Don't overflow when splicing

Testcase added.
This commit is contained in:
Benjamin Otte 2020-07-06 03:35:17 +02:00
parent fc770a383a
commit 3d931b4fe2
2 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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 ();
}