talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 2b5bf3d617f15cb25dc562fb1e2d895080fb6f3c
parent 4bfea623b0e391cb1ebd709cc40466ec40db3f11
Author: wwp <wwp@free.fr>
Date:   Tue, 22 May 2018 19:12:36 +0200

Fix few unchecked return values reported by Coverity:
1434187, 1434189, 1434192, 1434193, 1434195, 1434196, 1434198, 1434200, 1434202, 1434203
And few more. Change few silent returns into debug ones (cm_return_if_fail).

Diffstat:
Msrc/addr_compl.c | 9+++++----
Msrc/addrduplicates.c | 7++-----
Msrc/compose.c | 7++-----
Msrc/gtk/combobox.c | 5+++--
Msrc/gtk/foldersort.c | 9++++++---
Msrc/mimeview.c | 9++++++---
Msrc/prefs_folder_column.c | 146++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/prefs_summary_column.c | 134++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/prefs_toolbar.c | 9+++++----
Msrc/uri_opener.c | 6+++---
10 files changed, 172 insertions(+), 169 deletions(-)

diff --git a/src/addr_compl.c b/src/addr_compl.c @@ -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 */ diff --git a/src/addrduplicates.c b/src/addrduplicates.c @@ -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)?"), diff --git a/src/compose.c b/src/compose.c @@ -9214,9 +9214,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; @@ -9277,8 +9275,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); diff --git a/src/gtk/combobox.c b/src/gtk/combobox.c @@ -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; diff --git a/src/gtk/foldersort.c b/src/gtk/foldersort.c @@ -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; diff --git a/src/mimeview.c b/src/mimeview.c @@ -663,7 +663,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 { @@ -691,7 +692,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) { @@ -2364,7 +2366,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 { diff --git a/src/prefs_folder_column.c b/src/prefs_folder_column.c @@ -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? */ } diff --git a/src/prefs_summary_column.c b/src/prefs_summary_column.c @@ -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); } diff --git a/src/prefs_toolbar.c b/src/prefs_toolbar.c @@ -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) diff --git a/src/uri_opener.c b/src/uri_opener.c @@ -301,7 +301,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); } @@ -362,8 +363,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)) {