[gtk/listmodel-get-item: 3/4] selectionfiltermodel: Fix an oversight




commit a526daf3100c2c482dbc2ef4888f6a88e66a8182
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jun 11 15:37:16 2021 -0400

    selectionfiltermodel: Fix an oversight
    
    When the position is out of range, get_item needs
    to return NULL.
    
    Fixes: #4024

 gtk/gtkselectionfiltermodel.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkselectionfiltermodel.c b/gtk/gtkselectionfiltermodel.c
index 46cde1e965..398b88bc30 100644
--- a/gtk/gtkselectionfiltermodel.c
+++ b/gtk/gtkselectionfiltermodel.c
@@ -64,10 +64,10 @@ gtk_selection_filter_model_get_n_items (GListModel *list)
 {
   GtkSelectionFilterModel *self = GTK_SELECTION_FILTER_MODEL (list);
 
-  if (self->selection)
-    return gtk_bitset_get_size (self->selection);
+  if (!self->selection)
+    return 0;
 
-  return 0;
+  return gtk_bitset_get_size (self->selection);
 }
 
 static gpointer
@@ -76,6 +76,12 @@ gtk_selection_filter_model_get_item (GListModel *list,
 {
   GtkSelectionFilterModel *self = GTK_SELECTION_FILTER_MODEL (list);
 
+  if (!self->selection)
+    return NULL;
+
+  if (position >= gtk_bitset_get_size (self->selection))
+    return NULL;
+
   position = gtk_bitset_get_nth (self->selection, position);
 
   return g_list_model_get_item (G_LIST_MODEL (self->model), position);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]