Coverity fixes
authorColin Leroy <colin@colino.net>
Tue, 10 Jun 2014 09:36:16 +0000 (11:36 +0200)
committerColin Leroy <colin@colino.net>
Tue, 10 Jun 2014 09:36:16 +0000 (11:36 +0200)
src/procmime.c
src/statusbar.c
src/summary_search.c
src/summaryview.c
src/wizard.c

index 36bff67..2275c89 100644 (file)
@@ -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) {
index 48a2284..4ced87f 100644 (file)
@@ -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) {
index 97adcd4..a085520 100644 (file)
@@ -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) {
index 05c40b6..2c3e345 100644 (file)
@@ -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)");         
index 1686aff..0974120 100644 (file)
@@ -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)"));