From 35e2085f2be6d228a37160220a431cb38c562876 Mon Sep 17 00:00:00 2001 From: Colin Leroy Date: Tue, 10 Jun 2014 11:36:16 +0200 Subject: [PATCH] Coverity fixes --- src/procmime.c | 11 ++++++++++- src/statusbar.c | 2 +- src/summary_search.c | 5 ++++- src/summaryview.c | 5 ++++- src/wizard.c | 20 +++++++------------- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/procmime.c b/src/procmime.c index 36bff67e3..2275c8991 100644 --- a/src/procmime.c +++ b/src/procmime.c @@ -362,6 +362,7 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo) } if (fseek(infp, mimeinfo->offset, SEEK_SET) < 0) { perror("fseek"); + procmime_fclose(infp); return FALSE; } @@ -1458,6 +1459,7 @@ static void procmime_parse_message_rfc822(MimeInfo *mimeinfo, gboolean short_sca } if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) { FILE_OP_ERROR(mimeinfo->data.filename, "fseek"); + procmime_fclose(fp); return; } procheader_get_header_fields(fp, hentry); @@ -1532,7 +1534,11 @@ static void procmime_parse_disposition_notification(MimeInfo *mimeinfo, FILE_OP_ERROR(mimeinfo->data.filename, "fopen"); return; } - fseek(fp, mimeinfo->offset, SEEK_SET); + if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) { + FILE_OP_ERROR(mimeinfo->data.filename, "fseek"); + procmime_fclose(fp); + return; + } if (original_msgid && disposition_notification_hdr) { hentry[0].body = g_strdup(original_msgid); @@ -1660,6 +1666,7 @@ static void procmime_parse_multipart(MimeInfo *mimeinfo, gboolean short_scan) if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) { FILE_OP_ERROR(mimeinfo->data.filename, "fseek"); + procmime_fclose(fp); return; } @@ -2488,6 +2495,7 @@ static gint procmime_write_message_rfc822(MimeInfo *mimeinfo, FILE *fp) } if (fseek(infp, mimeinfo->offset, SEEK_SET) < 0) { FILE_OP_ERROR(mimeinfo->data.filename, "fseek"); + procmime_fclose(infp); return -1; } while (SC_FGETS(buf, sizeof(buf), infp) == buf) { @@ -2564,6 +2572,7 @@ static gint procmime_write_multipart(MimeInfo *mimeinfo, FILE *fp) } if (fseek(infp, mimeinfo->offset, SEEK_SET) < 0) { FILE_OP_ERROR(mimeinfo->data.filename, "fseek"); + procmime_fclose(infp); return -1; } while (SC_FGETS(buf, sizeof(buf), infp) == buf) { diff --git a/src/statusbar.c b/src/statusbar.c index 48a2284e0..4ced87f32 100644 --- a/src/statusbar.c +++ b/src/statusbar.c @@ -176,7 +176,7 @@ void statusbar_progress_all (gint done, gint total, gint step) g_snprintf(buf, sizeof(buf), format, done, total); gtk_progress_bar_set_text(progressbar, buf); gtk_progress_bar_set_fraction(progressbar, - (total == 0) ? 0 : (gfloat)done / (gfloat)total); + (gfloat)done / (gfloat)total); if (!gtk_widget_get_visible(GTK_WIDGET(progressbar))) gtk_widget_show(GTK_WIDGET(progressbar)); } else if (total == 0) { diff --git a/src/summary_search.c b/src/summary_search.c index 97adcd40a..a08552049 100644 --- a/src/summary_search.c +++ b/src/summary_search.c @@ -807,7 +807,10 @@ static void summary_search_execute(gboolean backward, gboolean search_all) msginfo = gtk_cmctree_node_get_row_data(ctree, node); - matched = summary_search_verify_match(msginfo); + if (msginfo) + matched = summary_search_verify_match(msginfo); + else + matched = FALSE; if (matched) { if (search_all) { diff --git a/src/summaryview.c b/src/summaryview.c index 05c40b68e..2c3e345a1 100644 --- a/src/summaryview.c +++ b/src/summaryview.c @@ -2505,6 +2505,8 @@ static void summary_set_marks_func(GtkCMCTree *ctree, GtkCMCTreeNode *node, msginfo = gtk_cmctree_node_get_row_data(ctree, node); + cm_return_if_fail(msginfo != NULL); + if (MSG_IS_DELETED(msginfo->flags)) summaryview->deleted++; @@ -3360,7 +3362,8 @@ static inline void summary_set_header(SummaryView *summaryview, gchar *text[], from_text = msginfo->from; else { from_text = msginfo->from; - extract_address(from_text); + if (from_text) + extract_address(from_text); } if (!from_text) _("(No From)"); diff --git a/src/wizard.c b/src/wizard.c index 1686affca..097412025 100644 --- a/src/wizard.c +++ b/src/wizard.c @@ -329,8 +329,7 @@ static gchar *get_name_for_mail(void) gchar *tmp = NULL, *new = NULL; \ if (str != NULL) { \ tmp = g_strdup(str); \ - if (strstr(str, "$USERNAME")) { \ - tmp = g_strdup(str); \ + if (strstr(tmp, "$USERNAME")) { \ *strstr(tmp, "$USERNAME") = '\0'; \ new = g_strconcat(tmp, g_get_real_name(), \ strstr(str, "$USERNAME")+strlen("$USERNAME"), \ @@ -340,8 +339,7 @@ static gchar *get_name_for_mail(void) str = new; \ new = NULL; \ } \ - if (strstr(str, "$LOGIN")) { \ - tmp = g_strdup(str); \ + if (strstr(tmp, "$LOGIN")) { \ *strstr(tmp, "$LOGIN") = '\0'; \ new = g_strconcat(tmp, g_get_user_name(), \ strstr(str, "$LOGIN")+strlen("$LOGIN"), \ @@ -351,8 +349,7 @@ static gchar *get_name_for_mail(void) str = new; \ new = NULL; \ } \ - if (strstr(str, "$EMAIL")) { \ - tmp = g_strdup(str); \ + if (strstr(tmp, "$EMAIL")) { \ *strstr(tmp, "$EMAIL") = '\0'; \ new = g_strconcat(tmp, tmpl.email, \ strstr(str, "$EMAIL")+strlen("$EMAIL"), \ @@ -362,8 +359,7 @@ static gchar *get_name_for_mail(void) str = new; \ new = NULL; \ } \ - if (strstr(str, "$NAME_MAIL")) { \ - tmp = g_strdup(str); \ + if (strstr(tmp, "$NAME_MAIL")) { \ *strstr(tmp, "$NAME_MAIL") = '\0'; \ new = g_strconcat(tmp, get_name_for_mail(), \ strstr(str, "$NAME_MAIL")+strlen("$NAME_MAIL"), \ @@ -373,8 +369,7 @@ static gchar *get_name_for_mail(void) str = new; \ new = NULL; \ } \ - if (strstr(str, "$DEFAULTDOMAIN")) { \ - tmp = g_strdup(str); \ + if (strstr(tmp, "$DEFAULTDOMAIN")) { \ *strstr(tmp, "$DEFAULTDOMAIN") = '\0'; \ new = g_strconcat(tmp, wizard_get_default_domain_name(), \ strstr(str, "$DEFAULTDOMAIN")+strlen("$DEFAULTDOMAIN"), \ @@ -384,8 +379,7 @@ static gchar *get_name_for_mail(void) str = new; \ new = NULL; \ } \ - if (strstr(str, "$DOMAIN")) { \ - tmp = g_strdup(str); \ + if (strstr(tmp, "$DOMAIN")) { \ *strstr(tmp, "$DOMAIN") = '\0'; \ new = g_strconcat(tmp, tmpl.domain, \ strstr(str, "$DOMAIN")+strlen("$DOMAIN"), \ @@ -1369,7 +1363,7 @@ static void auto_configure_cb (GtkWidget *widget, gpointer data) address = gtk_editable_get_chars(GTK_EDITABLE(wizard->email), 0, -1); - if (strchr(address, '@') < 0) { + if (strchr(address, '@') == NULL) { g_free(address); gtk_label_set_text(GTK_LABEL(wizard->auto_configure_lbl), _("Failed (wrong address)")); -- 2.25.1