Fix few unchecked return values reported by Coverity:
authorwwp <wwp@free.fr>
Tue, 22 May 2018 17:12:36 +0000 (19:12 +0200)
committerwwp <wwp@free.fr>
Tue, 22 May 2018 17:12:36 +0000 (19:12 +0200)
1434187143418914341921434193143419514341961434198143420014342021434203
And few more. Change few silent returns into debug ones (cm_return_if_fail).

src/addr_compl.c
src/addrduplicates.c
src/compose.c
src/gtk/combobox.c
src/gtk/foldersort.c
src/mimeview.c
src/prefs_folder_column.c
src/prefs_summary_column.c
src/prefs_toolbar.c
src/uri_opener.c

index 8ce1177..713fd50 100644 (file)
@@ -1026,14 +1026,15 @@ static void addrcompl_add_entry( CompletionWindow *cw, gchar *address ) {
        gtk_grab_add( cw->window );
 
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(cw->list_view));
-       gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
+       if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
+               return;
 
-       if( cw->listCount == 1 ) {
+       if (cw->listCount == 1) {
                /* Select first row for now */
                gtk_tree_selection_select_iter(selection, &iter);
        }
 #ifndef GENERIC_UMPC
-       else if( cw->listCount == 2 ) {
+       else if (cw->listCount == 2) {
                if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter)) {
                        /* Move off first row */
                        gtk_tree_selection_select_iter(selection, &iter);
@@ -1216,7 +1217,7 @@ static void completion_window_apply_selection(GtkTreeView *list_view,
        GList *grp_emails = NULL;
 
        selection = gtk_tree_view_get_selection(list_view);
-       if (! gtk_tree_selection_get_selected(selection, &model, &iter))
+       if (!gtk_tree_selection_get_selected(selection, &model, &iter))
                return;
 
        /* First remove the idler */
index af3ad08..e6f1176 100644 (file)
@@ -514,8 +514,7 @@ static gboolean is_editing_entry_only_selection(void)
                return FALSE;
 
        selected = gtk_tree_selection_get_selected_rows(sel_detail,&model);
-       if(!selected)
-               return FALSE;
+       cm_return_val_if_fail(selected, FALSE);
 
        gtk_tree_model_get_iter(model, &iter, (GtkTreePath*)selected->data);
        g_list_foreach(selected, (GFunc)gtk_tree_path_free, NULL);
@@ -786,9 +785,7 @@ static void cb_del_btn_clicked(GtkButton *button, gpointer data)
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(detail_view));
 
        list = gtk_tree_selection_get_selected_rows(selection, &model);
-
-       if(!list)
-               return;
+       cm_return_if_fail(list);
 
        aval = alertpanel(_("Delete address(es)"),
                          _("Really delete the address(es)?"),
index e8bf9c0..7888cd4 100644 (file)
@@ -9192,9 +9192,7 @@ static void compose_attach_remove_selected(GtkAction *action, gpointer data)
 
        selection = gtk_tree_view_get_selection(tree_view);
        sel = gtk_tree_selection_get_selected_rows(selection, &model);
-
-       if (!sel) 
-               return;
+       cm_return_if_fail(sel);
 
        for (cur = sel; cur != NULL; cur = cur->next) {
                GtkTreePath *path = cur->data;
@@ -9255,8 +9253,7 @@ static void compose_attach_property(GtkAction *action, gpointer data)
                return;
 
        sel = gtk_tree_selection_get_selected_rows(selection, &model);
-       if (!sel)
-               return;
+       cm_return_if_fail(sel);
 
        path = (GtkTreePath *) sel->data;
        gtk_tree_model_get_iter(model, &iter, path);
index 4804960..151edae 100644 (file)
@@ -263,8 +263,9 @@ void combobox_set_sensitive(GtkComboBox *combobox, const guint index,
        
        if((model = gtk_combo_box_get_model(combobox)) == NULL)
                return;
-       
-       gtk_tree_model_get_iter_first(model, &iter);
+
+       if(gtk_tree_model_get_iter_first(model, &iter) == FALSE)
+               return;
        for(i=0; i<index; i++) {
                if(gtk_tree_model_iter_next(model, &iter) == FALSE)
                        return;
index 8160235..df0c0c1 100644 (file)
@@ -89,7 +89,8 @@ static void set_selected(FolderSortDialog *dialog)
 
        /* Get row number of the selected row */
        sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->folderlist));
-       gtk_tree_selection_get_selected(sel, &model, &iter);
+       if (!gtk_tree_selection_get_selected(sel, &model, &iter))
+               return;
        path = gtk_tree_model_get_path(model, &iter);
        indices = gtk_tree_path_get_indices(path);
        selected = indices[0];
@@ -115,7 +116,8 @@ static void moveup_clicked(GtkWidget *widget, FolderSortDialog *dialog)
 
        /* Get currently selected iter */
        sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->folderlist));
-       gtk_tree_selection_get_selected(sel, &model, &iter);
+       if (!gtk_tree_selection_get_selected(sel, &model, &iter))
+               return;
 
        /* Now get the iter above it, if any */
 #if GTK_CHECK_VERSION(3, 0, 0)
@@ -156,7 +158,8 @@ static void movedown_clicked(GtkWidget *widget, FolderSortDialog *dialog)
 
        /* Get currently selected iter */
        sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->folderlist));
-       gtk_tree_selection_get_selected(sel, &model, &iter);
+       if (!gtk_tree_selection_get_selected(sel, &model, &iter))
+               return;
 
        /* Now get the iter above it, if any */
        nextiter = iter;
index 9dd0f49..20d2312 100644 (file)
@@ -662,7 +662,8 @@ gint mimeview_get_selected_part_num(MimeView *mimeview)
        GtkTreePath *path;
        gint i = 0;
 
-       gtk_tree_model_get_iter_first(model, &iter);
+       if (!gtk_tree_model_get_iter_first(model, &iter))
+               return -1;
        path = gtk_tree_model_get_path(model, &iter);
        
        do {
@@ -690,7 +691,8 @@ void mimeview_select_part_num(MimeView *mimeview, gint i)
        if (i < 0)
                return;
        
-       gtk_tree_model_get_iter_first(model, &iter);
+       if (!gtk_tree_model_get_iter_first(model, &iter))
+               return;
        path = gtk_tree_model_get_path(model, &iter);
        
        while (x != i) {
@@ -2363,7 +2365,8 @@ static void icon_selected (MimeView *mimeview, gint num, MimeInfo *partinfo)
        GtkTreePath *path;
        MimeInfo *curr = NULL;
        
-       gtk_tree_model_get_iter_first(model, &iter);
+       if (!gtk_tree_model_get_iter_first(model, &iter))
+               return;
        path = gtk_tree_model_get_path(model, &iter);
        
        do {
index a37fb54..4ef90f5 100644 (file)
@@ -714,11 +714,11 @@ static FolderColumnType prefs_folder_column_get_column(GtkWidget *list, gint row
 
        if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row))
                return -1;
-       
+
        gtk_tree_model_get(model, &iter, 
                           SUMCOL_TYPE, &result,
                           -1);
-       
+
        return result;
 }
 
@@ -734,7 +734,7 @@ static GtkWidget *prefs_folder_column_list_view_create(const gchar *name)
        
        gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(list_view),
                                     prefs_common.use_stripes_everywhere);
-       
+
        selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
        gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
 
@@ -745,12 +745,12 @@ static GtkWidget *prefs_folder_column_list_view_create(const gchar *name)
                                               row_targets,
                                               G_N_ELEMENTS(row_targets), 
                                               GDK_ACTION_MOVE);
-                                           
+
        gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(list_view), 
                                             row_targets, 
                                             G_N_ELEMENTS(row_targets), 
                                             GDK_ACTION_MOVE);
-               
+
        g_signal_connect(G_OBJECT(list_view), "drag_data_get",
                         G_CALLBACK(drag_data_get),
                         model);
@@ -810,50 +810,50 @@ static void drag_data_received(GtkTreeView *tree_view, GdkDragContext *context,
        FolderColumnType type;
        GtkTreeModel *sel_model;
        gchar *name;
-       
+
        source = gtk_drag_get_source_widget(context);
-       
+
        if (source == GTK_WIDGET(tree_view)) {
        
                /*
                 * Same widget: re-order
                 */
                 
-               gtk_tree_selection_get_selected(gtk_tree_view_get_selection(tree_view),
-                                          NULL, &isel);
-               sel = gtk_tree_model_get_path(model, &isel);
-               gtk_tree_view_get_dest_row_at_pos(tree_view, x, y,
-                                                 &dst, &pos);
-
-               /* NOTE: dst is invalid if selection beyond last row, in that
-                * case move beyond last one (XXX_move_before(..., NULL)) */                                              
-
-               if (dst)                                                  
-                       gtk_tree_model_get_iter(model, &idst, dst);
-               else 
-                       gtk_list_store_move_before(GTK_LIST_STORE(model),
-                                                  &isel,
-                                                  NULL);
-
-               /* we do not drag if no valid dst and sel, and when
-                * dst and sel are the same (moving after or before
-                * itself doesn't change order...) */
-               if ((dst && sel) && gtk_tree_path_compare(sel, dst) != 0) {
-                       if (pos == GTK_TREE_VIEW_DROP_BEFORE
-                       ||  pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
+               if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(tree_view),
+                                          NULL, &isel)) {
+                       sel = gtk_tree_model_get_path(model, &isel);
+                       gtk_tree_view_get_dest_row_at_pos(tree_view, x, y,
+                                                         &dst, &pos);
+
+                       /* NOTE: dst is invalid if selection beyond last row, in that
+                        * case move beyond last one (XXX_move_before(..., NULL)) */
+
+                       if (dst)
+                               gtk_tree_model_get_iter(model, &idst, dst);
+                       else 
                                gtk_list_store_move_before(GTK_LIST_STORE(model),
                                                           &isel,
-                                                          &idst);
-                       else
-                               gtk_list_store_move_after(GTK_LIST_STORE(model),
-                                                         &isel,
-                                                         &idst);
-                       
-               } 
-               gtk_tree_path_free(dst);                                          
-               gtk_tree_path_free(sel);
+                                                          NULL);
+
+                       /* we do not drag if no valid dst and sel, and when
+                        * dst and sel are the same (moving after or before
+                        * itself doesn't change order...) */
+                       if ((dst && sel) && gtk_tree_path_compare(sel, dst) != 0) {
+                               if (pos == GTK_TREE_VIEW_DROP_BEFORE
+                               ||  pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
+                                       gtk_list_store_move_before(GTK_LIST_STORE(model),
+                                                                  &isel,
+                                                                  &idst);
+                               else
+                                       gtk_list_store_move_after(GTK_LIST_STORE(model),
+                                                                 &isel,
+                                                                 &idst);
+                       } 
+                       gtk_tree_path_free(dst);
+                       gtk_tree_path_free(sel);
+               }
                gtk_drag_finish(context, TRUE, FALSE, time);
-               
+
        } else if (source == folder_col.stock_list_view 
        ||         source == folder_col.shown_list_view) {
        
@@ -861,47 +861,47 @@ static void drag_data_received(GtkTreeView *tree_view, GdkDragContext *context,
                 * Other widget: change and update
                 */
 
-               
                /* get source information and remove */
-               gtk_tree_selection_get_selected(gtk_tree_view_get_selection(
+               if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(
                                                GTK_TREE_VIEW(source)),
-                                               &sel_model, &isel);
-               type = *((gint *) gtk_selection_data_get_data(data));
-               name = gettext(col_name[type]);
-               gtk_list_store_remove(GTK_LIST_STORE(sel_model), &isel);
-
-               /* get insertion position */
-               gtk_tree_view_get_dest_row_at_pos(tree_view, x, y, &dst, &pos);
-
-               /* NOTE: dst is invalid if insertion point beyond last row, 
-                * just append to list in that case (XXX_store_append()) */
-
-               if (dst) {
-                       gtk_tree_model_get_iter(model, &idst, dst);
-
-                       if (pos == GTK_TREE_VIEW_DROP_BEFORE
-                       ||  pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
-                               gtk_list_store_insert_before(GTK_LIST_STORE(model),
-                                                            &isel,
-                                                            &idst);
-                       else
-                               gtk_list_store_insert_after(GTK_LIST_STORE(model),
-                                                           &isel,
-                                                           &idst);
-               } else
-                       gtk_list_store_append(GTK_LIST_STORE(model),
-                                             &isel);
-               
-               gtk_list_store_set(GTK_LIST_STORE(model), &isel,
-                                  SUMCOL_NAME, name,
-                                  SUMCOL_TYPE, type, -1);
-               gtk_tree_path_free(dst);
+                                               &sel_model, &isel)) {
+                       type = *((gint *) gtk_selection_data_get_data(data));
+                       name = gettext(col_name[type]);
+                       gtk_list_store_remove(GTK_LIST_STORE(sel_model), &isel);
+
+                       /* get insertion position */
+                       gtk_tree_view_get_dest_row_at_pos(tree_view, x, y, &dst, &pos);
+
+                       /* NOTE: dst is invalid if insertion point beyond last row,
+                        * just append to list in that case (XXX_store_append()) */
+
+                       if (dst) {
+                               gtk_tree_model_get_iter(model, &idst, dst);
+
+                               if (pos == GTK_TREE_VIEW_DROP_BEFORE
+                               ||  pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
+                                       gtk_list_store_insert_before(GTK_LIST_STORE(model),
+                                                                    &isel,
+                                                                    &idst);
+                               else
+                                       gtk_list_store_insert_after(GTK_LIST_STORE(model),
+                                                                   &isel,
+                                                                   &idst);
+                       } else
+                               gtk_list_store_append(GTK_LIST_STORE(model),
+                                                     &isel);
+
+                       gtk_list_store_set(GTK_LIST_STORE(model), &isel,
+                                          SUMCOL_NAME, name,
+                                          SUMCOL_TYPE, type, -1);
+                       gtk_tree_path_free(dst);
+               }
                gtk_drag_finish(context, TRUE, FALSE, time);
        }
 
        prefs_folder_column_shown_set_active(FALSE);
        prefs_folder_column_stock_set_active(FALSE);
-       
+
        /* XXXX: should we call gtk_drag_finish() for other code paths? */
 }
 
index 39b6f80..fea0ac7 100644 (file)
@@ -825,48 +825,48 @@ static void drag_data_received(GtkTreeView *tree_view, GdkDragContext *context,
        SummaryColumnType type;
        GtkTreeModel *sel_model;
        gchar *name;
-       
+
        source = gtk_drag_get_source_widget(context);
-       
+
        if (source == GTK_WIDGET(tree_view)) {
        
                /*
                 * Same widget: re-order
                 */
-                
-               gtk_tree_selection_get_selected(gtk_tree_view_get_selection(tree_view),
-                                          NULL, &isel);
-               sel = gtk_tree_model_get_path(model, &isel);
-               gtk_tree_view_get_dest_row_at_pos(tree_view, x, y,
-                                                 &dst, &pos);
-
-               /* NOTE: dst is invalid if selection beyond last row, in that
-                * case move beyond last one (XXX_move_before(..., NULL)) */                                              
-
-               if (dst)                                                  
-                       gtk_tree_model_get_iter(model, &idst, dst);
-               else 
-                       gtk_list_store_move_before(GTK_LIST_STORE(model),
-                                                  &isel,
-                                                  NULL);
-
-               /* we do not drag if no valid dst and sel, and when
-                * dst and sel are the same (moving after or before
-                * itself doesn't change order...) */
-               if ((dst && sel) && gtk_tree_path_compare(sel, dst) != 0) {
-                       if (pos == GTK_TREE_VIEW_DROP_BEFORE
-                       ||  pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
+
+               if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(tree_view),
+                                          NULL, &isel)) {
+                       sel = gtk_tree_model_get_path(model, &isel);
+                       gtk_tree_view_get_dest_row_at_pos(tree_view, x, y,
+                                                         &dst, &pos);
+
+                       /* NOTE: dst is invalid if selection beyond last row, in that
+                        * case move beyond last one (XXX_move_before(..., NULL)) */
+
+                       if (dst)
+                               gtk_tree_model_get_iter(model, &idst, dst);
+                       else 
                                gtk_list_store_move_before(GTK_LIST_STORE(model),
                                                           &isel,
-                                                          &idst);
-                       else
-                               gtk_list_store_move_after(GTK_LIST_STORE(model),
-                                                         &isel,
-                                                         &idst);
-                       
-               } 
-               gtk_tree_path_free(dst);                                          
-               gtk_tree_path_free(sel);
+                                                          NULL);
+
+                       /* we do not drag if no valid dst and sel, and when
+                        * dst and sel are the same (moving after or before
+                        * itself doesn't change order...) */
+                       if ((dst && sel) && gtk_tree_path_compare(sel, dst) != 0) {
+                               if (pos == GTK_TREE_VIEW_DROP_BEFORE
+                               ||  pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
+                                       gtk_list_store_move_before(GTK_LIST_STORE(model),
+                                                                  &isel,
+                                                                  &idst);
+                               else
+                                       gtk_list_store_move_after(GTK_LIST_STORE(model),
+                                                                 &isel,
+                                                                 &idst);
+                       } 
+                       gtk_tree_path_free(dst);
+                       gtk_tree_path_free(sel);
+               }
                gtk_drag_finish(context, TRUE, FALSE, time);
                
        } else if (source == summary_col.stock_list_view 
@@ -876,41 +876,41 @@ static void drag_data_received(GtkTreeView *tree_view, GdkDragContext *context,
                 * Other widget: change and update
                 */
 
-               
                /* get source information and remove */
-               gtk_tree_selection_get_selected(gtk_tree_view_get_selection(
+               if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(
                                                GTK_TREE_VIEW(source)),
-                                               &sel_model, &isel);
-               type = *((gint *) gtk_selection_data_get_data(data));
-               name = gettext(col_name[type]);
-               gtk_list_store_remove(GTK_LIST_STORE(sel_model), &isel);
-
-               /* get insertion position */
-               gtk_tree_view_get_dest_row_at_pos(tree_view, x, y, &dst, &pos);
-
-               /* NOTE: dst is invalid if insertion point beyond last row, 
-                * just append to list in that case (XXX_store_append()) */
-
-               if (dst) {
-                       gtk_tree_model_get_iter(model, &idst, dst);
-
-                       if (pos == GTK_TREE_VIEW_DROP_BEFORE
-                       ||  pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
-                               gtk_list_store_insert_before(GTK_LIST_STORE(model),
-                                                            &isel,
-                                                            &idst);
-                       else
-                               gtk_list_store_insert_after(GTK_LIST_STORE(model),
-                                                           &isel,
-                                                           &idst);
-               } else
-                       gtk_list_store_append(GTK_LIST_STORE(model),
-                                             &isel);
-               
-               gtk_list_store_set(GTK_LIST_STORE(model), &isel,
-                                  SUMCOL_NAME, name,
-                                  SUMCOL_TYPE, type, -1);
-               gtk_tree_path_free(dst);
+                                               &sel_model, &isel)) {
+                       type = *((gint *) gtk_selection_data_get_data(data));
+                       name = gettext(col_name[type]);
+                       gtk_list_store_remove(GTK_LIST_STORE(sel_model), &isel);
+
+                       /* get insertion position */
+                       gtk_tree_view_get_dest_row_at_pos(tree_view, x, y, &dst, &pos);
+
+                       /* NOTE: dst is invalid if insertion point beyond last row, 
+                        * just append to list in that case (XXX_store_append()) */
+
+                       if (dst) {
+                               gtk_tree_model_get_iter(model, &idst, dst);
+
+                               if (pos == GTK_TREE_VIEW_DROP_BEFORE
+                               ||  pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
+                                       gtk_list_store_insert_before(GTK_LIST_STORE(model),
+                                                                    &isel,
+                                                                    &idst);
+                               else
+                                       gtk_list_store_insert_after(GTK_LIST_STORE(model),
+                                                                   &isel,
+                                                                   &idst);
+                       } else
+                               gtk_list_store_append(GTK_LIST_STORE(model),
+                                                     &isel);
+
+                       gtk_list_store_set(GTK_LIST_STORE(model), &isel,
+                                          SUMCOL_NAME, name,
+                                          SUMCOL_TYPE, type, -1);
+                       gtk_tree_path_free(dst);
+               }
                gtk_drag_finish(context, TRUE, FALSE, time);
        }
 
index cc56483..464012b 100644 (file)
@@ -370,10 +370,11 @@ static void prefs_toolbar_set_displayed(ToolbarPage *prefs_toolbar)
        }
 
        /* select first */
-       gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
-       gtk_tree_selection_select_iter(gtk_tree_view_get_selection
-                                               (list_view_set),
-                                      &iter);
+       if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) {
+               gtk_tree_selection_select_iter(gtk_tree_view_get_selection
+                                                       (list_view_set),
+                                              &iter);
+       }
 }
 
 static void add_item_to_plugin_combo(gpointer key, gpointer data, gpointer combo_box)
index 4929b52..8c47de1 100644 (file)
@@ -303,7 +303,8 @@ static void uri_opener_load_uris (void)
        g_object_unref(opener.urilist);
        
        model = gtk_tree_view_get_model(GTK_TREE_VIEW(opener.urilist));
-       gtk_tree_model_get_iter_first(model, &iter);
+       if (!gtk_tree_model_get_iter_first(model, &iter))
+               return;
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(opener.urilist));
        gtk_tree_selection_select_iter(selection, &iter);
 }
@@ -364,8 +365,7 @@ static void uri_opener_open_cb(GtkWidget *widget,
 
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(opener.urilist));
        selected  = gtk_tree_selection_get_selected_rows(selection, &model);
-       if(!selected)
-               return;
+       cm_return_if_fail(selected);
                
        for(cur = selected; cur != NULL; cur = g_list_next(cur))
        {