[gtk/selection-filter-fixes: 1/2] selectionfilter: Fix bugs in signal translation
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/selection-filter-fixes: 1/2] selectionfilter: Fix bugs in signal translation
- Date: Fri, 3 Jul 2020 15:08:04 +0000 (UTC)
commit 15edd4cae92083629b62bd2a0bee6cadc213baba
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Jul 3 09:53:27 2020 -0400
selectionfilter: Fix bugs in signal translation
When the position is 0, we can't check for unchanged
elements below with gtk_bitset_size_in_range. And
we don't need to, either.
And be careful when translating [start,length]
intervals to [first,last] ones. Off-by-one errors
lurk everywhere.
gtk/gtkselectionfiltermodel.c | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtkselectionfiltermodel.c b/gtk/gtkselectionfiltermodel.c
index 5cf094e1a3..f28fcc0ae5 100644
--- a/gtk/gtkselectionfiltermodel.c
+++ b/gtk/gtkselectionfiltermodel.c
@@ -107,15 +107,20 @@ gtk_selection_filter_model_items_changed_cb (GListModel *model,
GtkSelectionFilterModel *self)
{
GtkBitset *selection;
- guint sel_position;
- guint sel_removed;
- guint sel_added;
+ guint sel_position = 0;
+ guint sel_removed = 0;
+ guint sel_added = 0;
selection = gtk_selection_model_get_selection (self->model);
- sel_position = gtk_bitset_get_size_in_range (self->selection, 0, position - 1);
- sel_removed = gtk_bitset_get_size_in_range (self->selection, position, position + removed);
- sel_added = gtk_bitset_get_size_in_range (selection, position, position + added);
+ if (position > 0)
+ sel_position = gtk_bitset_get_size_in_range (self->selection, 0, position - 1);
+
+ if (removed > 0)
+ sel_removed = gtk_bitset_get_size_in_range (self->selection, position, position + removed - 1);
+
+ if (added > 0)
+ sel_added = gtk_bitset_get_size_in_range (selection, position, position + added - 1);
gtk_bitset_unref (self->selection);
self->selection = gtk_bitset_copy (selection);
@@ -133,19 +138,20 @@ gtk_selection_filter_model_selection_changed_cb (GListModel *model,
GtkSelectionFilterModel *self)
{
GtkBitset *selection;
- guint sel_position;
- guint sel_removed;
- guint sel_added;
+ guint sel_position = 0;
+ guint sel_removed = 0;
+ guint sel_added = 0;
selection = gtk_selection_model_get_selection (self->model);
- sel_position = gtk_bitset_get_size_in_range (self->selection, 0, position - 1);
- sel_removed = gtk_bitset_get_size_in_range (self->selection, position, position + n_items);
- sel_added = gtk_bitset_get_size_in_range (selection, position, position + n_items);
+ if (position > 0)
+ sel_position = gtk_bitset_get_size_in_range (self->selection, 0, position - 1);
+
+ sel_removed = gtk_bitset_get_size_in_range (self->selection, position, position + n_items - 1);
+ sel_added = gtk_bitset_get_size_in_range (selection, position, position + n_items - 1);
gtk_bitset_unref (self->selection);
self->selection = gtk_bitset_copy (selection);
-
gtk_bitset_unref (selection);
if (sel_removed > 0 || sel_added > 0)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]