talons

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

commit 767368e8981d8c65d2bf0e800941c9f4713376f8
parent 168e74c7dfb9b4ccddb06b9b28a2a477c75647df
Author: Colin Leroy <colin@colino.net>
Date:   Thu,  5 Jun 2014 21:29:31 +0200

More Coverity fixes

Diffstat:
Msrc/compose.c | 32+++++++++++++++-----------------
Msrc/edittags.c | 2+-
Msrc/filtering.c | 5++++-
Msrc/folder.c | 12++++++------
Msrc/folderview.c | 27+++++++++++++--------------
Msrc/grouplistdialog.c | 5+++--
Msrc/gtk/gtkcmclist.c | 15+++++++++------
Msrc/gtk/gtkcmctree.c | 11++++++-----
Msrc/gtk/gtkunit.c | 9++-------
Msrc/gtk/gtkutils.c | 10+++++-----
Msrc/gtk/prefswindow.c | 13++++++++-----
Msrc/gtk/quicksearch.c | 2+-
12 files changed, 73 insertions(+), 70 deletions(-)

diff --git a/src/compose.c b/src/compose.c @@ -3207,7 +3207,7 @@ static gboolean is_subscription(const gchar *ml_post, const gchar *from) *(strstr(left_from, "@")) = '\0'; } - if (left_ml && left_from && right_ml && right_from + if (right_ml && right_from && !strncmp(left_from, left_ml, strlen(left_ml)) && !strcmp(right_from, right_ml)) { result = TRUE; @@ -3575,7 +3575,6 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi gint len; FILE *fp; gboolean prev_autowrap; - gboolean badtxt = FALSE; struct stat file_stat; int ret; GString *file_contents = NULL; @@ -3675,10 +3674,7 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi fclose(fp); - if (badtxt) - return COMPOSE_INSERT_INVALID_CHARACTER; - else - return COMPOSE_INSERT_SUCCESS; + return COMPOSE_INSERT_SUCCESS; } static gboolean compose_attach_append(Compose *compose, const gchar *file, @@ -5757,8 +5753,11 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file) (tmp, CS_INTERNAL, conv_get_locale_charset_str()); g_free(tmp); - if (!chars) return -1; - + if (!chars) { + fclose(fp); + claws_unlink(file); + return -1; + } /* write body */ len = strlen(chars); if (fwrite(chars, sizeof(gchar), len, fp) != len) { @@ -6139,13 +6138,14 @@ static int compose_add_attachments(Compose *compose, MimeInfo *parent) } continue; } + if (g_stat(ainfo->file, &statbuf) < 0) + return -1; + mimepart = procmime_mimeinfo_new(); mimepart->content = MIMECONTENT_FILE; mimepart->data.filename = g_strdup(ainfo->file); mimepart->tmp = FALSE; /* or we destroy our attachment */ mimepart->offset = 0; - - g_stat(ainfo->file, &statbuf); mimepart->length = statbuf.st_size; type = g_strdup(ainfo->content_type); @@ -7375,8 +7375,9 @@ static void compose_dict_changed(void *data) { Compose *compose = (Compose *) data; - if(compose->gtkaspell && - compose->gtkaspell->recheck_when_changing_dict == FALSE) + if(!compose->gtkaspell) + return; + if(compose->gtkaspell->recheck_when_changing_dict == FALSE) return; gtkaspell_highlight_all(compose->gtkaspell); @@ -8924,7 +8925,7 @@ static void compose_attach_property(GtkAction *action, gpointer data) gtk_widget_hide(attach_prop.window); gtk_window_set_modal(GTK_WINDOW(attach_prop.window), FALSE); - if (cancelled) + if (cancelled) break; entry_text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry)); @@ -9530,7 +9531,7 @@ static void account_activated(GtkComboBox *optmenu, gpointer data) /* Get ID of active account in the combo box */ menu = gtk_combo_box_get_model(optmenu); - gtk_combo_box_get_active_iter(optmenu, &iter); + cm_return_if_fail(gtk_combo_box_get_active_iter(optmenu, &iter)); gtk_tree_model_get(menu, &iter, 1, &account_id, -1); ac = account_find_from_id(account_id); @@ -11192,10 +11193,7 @@ static void compose_insert_drag_received_cb (GtkWidget *widget, g_list_free(list); gtk_drag_finish(drag_context, TRUE, FALSE, time); return; - } else { - return; } - gtk_drag_finish(drag_context, TRUE, FALSE, time); } static void compose_header_drag_received_cb (GtkWidget *widget, diff --git a/src/edittags.c b/src/edittags.c @@ -67,7 +67,7 @@ static gint tag_cmp_func (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, g return name2 == NULL ? 0:1; if (name2 == NULL) - return name1 == NULL ? 0:1; + return 1; return g_utf8_collate(name1,name2); } diff --git a/src/filtering.c b/src/filtering.c @@ -508,7 +508,10 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info) abf = book->rawDataSource; #endif /* get the header */ - procheader_get_header_from_msginfo(info, buf, sizeof(buf), action->header); + if (procheader_get_header_from_msginfo(info, buf, + sizeof(buf), action->header) < 0) + return FALSE; + header = procheader_parse_header(buf); /* add all addresses that are not already in */ diff --git a/src/folder.c b/src/folder.c @@ -2746,7 +2746,8 @@ void folder_item_write_cache(FolderItem *item) filemode = prefs->folder_chmod; if (filemode & S_IRGRP) filemode |= S_IWGRP; if (filemode & S_IROTH) filemode |= S_IWOTH; - chmod(cache_file, filemode); + if (cache_file != NULL) + chmod(cache_file, filemode); } } else { item->cache_dirty = FALSE; @@ -3605,13 +3606,12 @@ static gint do_copy_msgs(FolderItem *dest, GSList *msglist, gboolean remove_sour } } } - - if (msginfo->planned_download - == POP3_PARTIAL_DLOAD_DELE) { + if (newmsginfo != NULL + && msginfo->planned_download == POP3_PARTIAL_DLOAD_DELE) { partial_mark_for_delete(newmsginfo); } - if (msginfo->planned_download - == POP3_PARTIAL_DLOAD_DLOAD) { + if (newmsginfo != NULL + && msginfo->planned_download == POP3_PARTIAL_DLOAD_DLOAD) { partial_mark_for_download(newmsginfo); } if (!MSG_IS_POSTFILTERED (msginfo->flags)) { diff --git a/src/folderview.c b/src/folderview.c @@ -2670,22 +2670,21 @@ static void folderview_drag_data_get(GtkWidget *widget, FolderView *folderview) { FolderItem *item; - GList *cur; + GList *sel; gchar *source = NULL; if (info == TARGET_DUMMY) { - for (cur = GTK_CMCLIST(folderview->ctree)->selection; - cur != NULL; cur = cur->next) { - item = gtk_cmctree_node_get_row_data - (GTK_CMCTREE(folderview->ctree), - GTK_CMCTREE_NODE(cur->data)); - if (item) { - source = g_strdup_printf ("FROM_OTHER_FOLDER%s", folder_item_get_identifier(item)); - gtk_selection_data_set(selection_data, - gtk_selection_data_get_target(selection_data), 8, - source, strlen(source)); - break; - } else - return; + sel = GTK_CMCLIST(folderview->ctree)->selection; + if (!sel) + return; + + item = gtk_cmctree_node_get_row_data + (GTK_CMCTREE(folderview->ctree), + GTK_CMCTREE_NODE(sel->data)); + if (item) { + source = g_strdup_printf ("FROM_OTHER_FOLDER%s", folder_item_get_identifier(item)); + gtk_selection_data_set(selection_data, + gtk_selection_data_get_target(selection_data), 8, + source, strlen(source)); } } else { g_warning("unknown info %d\n", info); diff --git a/src/grouplistdialog.c b/src/grouplistdialog.c @@ -567,8 +567,9 @@ static gboolean button_press_cb(GtkCMCTree *ctree, GdkEventButton *button, if (button->type != GDK_BUTTON_PRESS) return TRUE; if (button->button != 1) return TRUE; - gtk_cmclist_get_selection_info(GTK_CMCLIST(ctree), - button->x, button->y, &row, &col); + if (!gtk_cmclist_get_selection_info(GTK_CMCLIST(ctree), + button->x, button->y, &row, &col)) + return TRUE; node = gtk_cmctree_node_nth(ctree, row); if (!node) return TRUE; diff --git a/src/gtk/gtkcmclist.c b/src/gtk/gtkcmclist.c @@ -3727,6 +3727,7 @@ toggle_row (GtkCMCList *clist, row, column, event); return; } + break; case GTK_SELECTION_BROWSE: g_signal_emit (G_OBJECT (clist), clist_signals[SELECT_ROW], 0, row, column, event); @@ -4641,7 +4642,6 @@ gtk_cmclist_realize (GtkWidget *widget) #endif /* main window */ - window = gtk_widget_get_window (widget); window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); gdk_window_set_user_data (window, clist); @@ -5792,13 +5792,14 @@ draw_row (GtkCMCList *clist, return; widget = GTK_WIDGET (clist); - style = clist_row->style ? clist_row->style : gtk_widget_get_style (widget); /* if the function is passed the pointer to the row instead of null, * it avoids this expensive lookup */ if (!clist_row) clist_row = ROW_ELEMENT (clist, row)->data; + style = clist_row->style ? clist_row->style : gtk_widget_get_style (widget); + /* rectangle of the entire row */ row_rectangle.x = 0; row_rectangle.y = ROW_TOP_YPIXEL (clist, row); @@ -6324,7 +6325,6 @@ hadjustment_value_changed (GtkAdjustment *adjustment, { GtkCMCList *clist; GtkContainer *container; - GdkRectangle area; gint i; gint y = 0; gint value; @@ -6385,7 +6385,7 @@ hadjustment_value_changed (GtkAdjustment *adjustment, focus_row = clist->focus_row; clist->focus_row = -1; - draw_rows (clist, &area); + draw_rows (clist, NULL); clist->focus_row = focus_row; cairo_rectangle(cr, 0, y, clist->clist_window_width + 1, @@ -7138,6 +7138,7 @@ scroll_vertical (GtkCMCList *clist, default: break; } + /* fallback is intentional */ default: if (old_focus_row != clist->focus_row && !(clist->selection_mode == GTK_SELECTION_MULTIPLE && @@ -7420,6 +7421,9 @@ gtk_cmclist_merge (GtkCMCList *clist, c = &z; + if (!a && !b) + return NULL; + while (a || b) { if (a && !b) @@ -7442,8 +7446,7 @@ gtk_cmclist_merge (GtkCMCList *clist, { cmp = clist->compare (clist, GTK_CMCLIST_ROW (a), GTK_CMCLIST_ROW (b)); if ((cmp >= 0 && clist->sort_type == GTK_SORT_DESCENDING) || - (cmp <= 0 && clist->sort_type == GTK_SORT_ASCENDING) || - (a && !b)) + (cmp <= 0 && clist->sort_type == GTK_SORT_ASCENDING)) { c->next = a; a->prev = c; diff --git a/src/gtk/gtkcmctree.c b/src/gtk/gtkcmctree.c @@ -617,6 +617,12 @@ draw_row (GtkCMCList *clist, cm_return_if_fail (clist != NULL); widget = GTK_WIDGET (clist); + + /* if the function is passed the pointer to the row instead of null, + * it avoids this expensive lookup */ + if (!clist_row) + clist_row = (g_list_nth (clist->row_list, row))->data; + style = clist_row->style ? clist_row->style : gtk_widget_get_style (widget); if (greybg.pixel == 0 && @@ -648,11 +654,6 @@ draw_row (GtkCMCList *clist, ctree = GTK_CMCTREE (clist); - /* if the function is passed the pointer to the row instead of null, - * it avoids this expensive lookup */ - if (!clist_row) - clist_row = (g_list_nth (clist->row_list, row))->data; - /* rectangle of the entire row */ row_rectangle.x = 0; row_rectangle.y = ROW_TOP_YPIXEL (clist, row); diff --git a/src/gtk/gtkunit.c b/src/gtk/gtkunit.c @@ -569,16 +569,11 @@ gtk_param_unit_value_validate (GParamSpec *pspec, GtkParamSpecUnit *uspec = GTK_PARAM_SPEC_UNIT (pspec); gint oval = value->data[0].v_int; - if (uspec->allow_percent && value->data[0].v_int == CM_UNIT_PERCENT) - { - value->data[0].v_int = value->data[0].v_int; - } - else - { + if (uspec->allow_percent && value->data[0].v_int != CM_UNIT_PERCENT) { value->data[0].v_int = CLAMP (value->data[0].v_int, ispec->minimum, gtk_unit_get_number_of_units () - 1); - } + } return value->data[0].v_int != oval; } diff --git a/src/gtk/gtkutils.c b/src/gtk/gtkutils.c @@ -1099,7 +1099,8 @@ GtkWidget *xface_get_from_header(const gchar *o_xface) static gchar *xpm_xface[XPM_XFACE_HEIGHT]; static gboolean xpm_xface_init = TRUE; gchar xface[2048]; - strncpy(xface, o_xface, sizeof(xface)); + strncpy(xface, o_xface, sizeof(xface) - 1); + xface[sizeof(xface) - 1] = '\0'; if (uncompface(xface) < 0) { g_warning("uncompface failed\n"); @@ -1590,8 +1591,8 @@ gint gtkut_list_view_get_selected_row(GtkWidget *list_view) for (row = 0; row < n_rows; row++) { GtkTreeIter itern; - gtk_tree_model_iter_nth_child(model, &itern, NULL, row); - if (gtkut_tree_iter_comp(model, &iter, &itern)) + if (gtk_tree_model_iter_nth_child(model, &itern, NULL, row) + && gtkut_tree_iter_comp(model, &iter, &itern)) return row; } @@ -2028,4 +2029,4 @@ gboolean auto_configure_service_sync(const gchar *service, const gchar *domain, g_object_unref(resolver); return result; } -#endif -\ No newline at end of file +#endif diff --git a/src/gtk/prefswindow.c b/src/gtk/prefswindow.c @@ -316,7 +316,7 @@ static void prefswindow_build_page(PrefsWindow *prefswindow, PrefsPage *page) } } -static void prefswindow_build_all_pages(PrefsWindow *prefswindow, GSList *prefs_pages) +static GSList *prefswindow_build_all_pages(PrefsWindow *prefswindow, GSList *prefs_pages) { GSList *cur; @@ -326,7 +326,7 @@ static void prefswindow_build_all_pages(PrefsWindow *prefswindow, GSList *prefs_ prefswindow_build_page(prefswindow, page); } - prefs_pages = g_slist_reverse(prefs_pages); + return g_slist_reverse(prefs_pages); } static void prefswindow_build_tree(GtkWidget *tree_view, GSList *prefs_pages, @@ -346,7 +346,7 @@ static void prefswindow_build_tree(GtkWidget *tree_view, GSList *prefs_pages, PrefsPage *page = (PrefsPage *)cur->data; FindNodeByName find_name; GtkTreeIter node, child; - PrefsTreeNode *prefs_node; + PrefsTreeNode *prefs_node = NULL; int i; /* each page tree component string */ @@ -384,7 +384,10 @@ static void prefswindow_build_tree(GtkWidget *tree_view, GSList *prefs_pages, } /* right now we have a node and its prefs_node */ - prefs_node->page = page; + if (!prefs_node) + g_warning("no prefs_node :/"); + else + prefs_node->page = page; /* parents "inherit" the max weight of the children */ do { @@ -416,7 +419,7 @@ static void prefswindow_build_tree(GtkWidget *tree_view, GSList *prefs_pages, GTK_SORT_DESCENDING); if (preload_pages) - prefswindow_build_all_pages(prefswindow, prefs_pages); + prefs_pages = prefswindow_build_all_pages(prefswindow, prefs_pages); /* select first one or its first child if necessary */ #ifndef GENERIC_UMPC diff --git a/src/gtk/quicksearch.c b/src/gtk/quicksearch.c @@ -1014,7 +1014,7 @@ void quicksearch_pass_key(QuickSearch *quicksearch, guint val, GdkModifierType m char *end = NULL; char *new = NULL; char key[7] = ""; - guint char_len = 0; + gint char_len = 0; if (gtk_editable_get_selection_bounds(GTK_EDITABLE(entry), NULL, NULL)) { /* remove selection */