Fix potential crashes in gtkut_tree_view_get_selected_pointer().
authorAndrej Kacian <ticho@claws-mail.org>
Sat, 3 Mar 2018 09:27:56 +0000 (10:27 +0100)
committerAndrej Kacian <ticho@claws-mail.org>
Sat, 3 Mar 2018 09:27:56 +0000 (10:27 +0100)
src/gtk/gtkutils.c

index 47b76df..5165ff1 100644 (file)
@@ -2003,15 +2003,23 @@ gpointer gtkut_tree_view_get_selected_pointer(GtkTreeView *view,
        cm_return_val_if_fail(view != NULL, NULL);
        cm_return_val_if_fail(column >= 0, NULL);
 
-       sel = gtk_tree_view_get_selection(view);
+       model = gtk_tree_view_get_model(view);
+       if (_model != NULL)
+               *_model = model;
 
-       cm_return_val_if_fail(
-                       gtk_tree_selection_count_selected_rows(sel) == 1,
-                       NULL);
+       sel = gtk_tree_view_get_selection(view);
+       if (_selection != NULL)
+               *_selection = sel;
 
-       if (!gtk_tree_selection_get_selected(sel, &model, &iter))
+       if (!gtk_tree_selection_get_selected(sel, NULL, &iter))
                return NULL; /* No row selected */
 
+       if (_iter != NULL)
+               *_iter = iter;
+
+       if (gtk_tree_selection_count_selected_rows(sel) > 1)
+               return NULL; /* Can't work with multiselect */
+
        cm_return_val_if_fail(
                        gtk_tree_model_get_n_columns(model) > column,
                        NULL);
@@ -2023,12 +2031,5 @@ gpointer gtkut_tree_view_get_selected_pointer(GtkTreeView *view,
 
        gtk_tree_model_get(model, &iter, column, &ptr, -1);
 
-       if (_model != NULL)
-               *_model = model;
-       if (_selection != NULL)
-               *_selection = sel;
-       if (_iter != NULL)
-               *_iter = iter;
-
        return ptr;
 }