Coverity fixes
authorColin Leroy <colin@colino.net>
Fri, 6 Jun 2014 14:14:26 +0000 (16:14 +0200)
committerColin Leroy <colin@colino.net>
Fri, 6 Jun 2014 14:14:26 +0000 (16:14 +0200)
12 files changed:
src/addr_compl.c
src/addressbook.c
src/common/ssl_certificate.c
src/prefs_account.c
src/prefs_common.c
src/prefs_filtering.c
src/prefs_themes.c
src/prefs_toolbar.c
src/printing.c
src/quote_fmt_parse.y
src/send_message.c
src/textview.c

index 1d7d65d..adcb7cc 100644 (file)
@@ -972,9 +972,10 @@ static void addrcompl_add_entry( CompletionWindow *cw, gchar *address ) {
        }
 #ifndef GENERIC_UMPC
        else if( cw->listCount == 2 ) {
-               gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
-               /* Move off first row */
-               gtk_tree_selection_select_iter(selection, &iter);
+               if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter)) {
+                       /* Move off first row */
+                       gtk_tree_selection_select_iter(selection, &iter);
+               }
        }
 #endif
 }
index a516b92..ffd6909 100644 (file)
@@ -3191,7 +3191,6 @@ static void addressbook_new_address_cb( GtkAction *action, gpointer data ) {
                                }
                                folder = addressbook_setup_subf( ds, _("New Contacts"), parentNode );
 
-                               pobj = gtk_cmctree_node_get_row_data(GTK_CMCTREE(addrbook.ctree), addrbook.treeSelected);
                                ds = addressbook_find_datasource( GTK_CMCTREE_NODE(addrbook.treeSelected) );
                                if (ds)
                                        abf = ds->rawDataSource;
index 0a8b828..c1e7dbf 100644 (file)
@@ -536,6 +536,9 @@ static guint check_cert(SSLCertificate *cert)
        else
                return (guint)-1;
 
+       if (fp == NULL)
+               return (guint)-1;
+
        if ((r = gnutls_import_X509_list_fp(fp, GNUTLS_X509_FMT_PEM, &ca_list, &max_ca)) < 0) {
                debug_print("CA import failed: %s\n", gnutls_strerror(r));
                fclose(fp);
index a03f500..bb9c07a 100644 (file)
@@ -3843,7 +3843,7 @@ static void auto_configure_cb (GtkWidget *widget, gpointer data)
 
        address = gtk_editable_get_chars(GTK_EDITABLE(basic_page.addr_entry), 0, -1);
 
-       if (strchr(address, '@') < 0) {
+       if (strchr(address, '@') == NULL) {
                g_free(address);
                gtk_label_set_text(GTK_LABEL(basic_page.auto_configure_lbl),
                           _("Failed (wrong address)"));
index 93fcce6..a417b0d 100644 (file)
@@ -1467,7 +1467,7 @@ void pref_set_textview_from_pref(GtkTextView *textview, const gchar *txt)
 
                pref_get_unescaped_pref(out, txt);
 
-               gtk_text_buffer_set_text(buffer, out?out:"", -1);
+               gtk_text_buffer_set_text(buffer, out, -1);
                g_free(out);
        }
 }
@@ -1486,7 +1486,7 @@ void pref_set_entry_from_pref(GtkEntry *entry, const gchar *txt)
 
                pref_get_unescaped_pref(out, txt);
 
-               gtk_entry_set_text(entry, out?out:"");
+               gtk_entry_set_text(entry, out);
                g_free(out);
        }
 }
index 4077324..662c375 100644 (file)
@@ -1437,10 +1437,8 @@ static void prefs_filtering_select_set(FilteringProp *prop)
        gtk_entry_set_text(GTK_ENTRY(filtering.cond_entry), matcher_str);
 
         action_str = filteringaction_list_to_string(prop->action_list);
-       if (matcher_str == NULL) {
-               return;
-       }
-       gtk_entry_set_text(GTK_ENTRY(filtering.action_entry), action_str);
+       if (action_str != NULL)
+               gtk_entry_set_text(GTK_ENTRY(filtering.action_entry), action_str);
 
        g_free(action_str);
        g_free(matcher_str);
index 9f02566..0b4ad1b 100644 (file)
@@ -704,7 +704,7 @@ static void prefs_themes_display_global_stats(const ThemesData *tdata)
                if (line[len - 1] == '\n') line[len - 1] = '\0'; \
        } \
        else { \
-               strcpy(line, _("Unknown")); \
+               g_strlcpy(line, _("Unknown"),sizeof(line)); \
        }
 
 static void prefs_themes_get_theme_info(ThemesData *tdata)
index 9969063..8504b79 100644 (file)
@@ -1635,10 +1635,10 @@ static gboolean icon_list_button_release(GtkWidget *widget,
                                               GdkEventButton *event,
                                               ToolbarPage *prefs_toolbar )
 {
-       static guint id = -1;
-       if (id >= 0) {
+       static guint id = 0;
+       if (id > 0) {
                g_source_remove(id);
-               id = -1;
+               id = 0;
        }
        id = g_timeout_add(100, ok_cb, prefs_toolbar);
        return FALSE;
index 369f922..e4cb1f1 100644 (file)
@@ -1281,7 +1281,8 @@ static void printing_layout_set_text_attributes(PrintData *print_data,
                                                        attr_color = (PangoAttrColor*) attr;
                                                        g_object_get(G_OBJECT(tag), "background-gdk",
                                                                     &color, NULL);
-                                                       if (printing_is_pango_gdk_color_equal(&(attr_color->color),
+                                                       if (color && 
+                                                           printing_is_pango_gdk_color_equal(&(attr_color->color),
                                                            color)) {
                                                                attr->end_index = printing_text_iter_get_offset_bytes(print_data, &iter);
                                                                pango_attr_list_insert(attr_list, attr);
index 3567ffa..4ad346b 100644 (file)
@@ -88,8 +88,8 @@ static void add_visibility(gboolean val)
                if (visible == NULL)
                        maxsize = 0;
        }
-
-       visible[stacksize - 1] = val;
+       if (visible != NULL)
+               visible[stacksize - 1] = val;
 }
 
 static void remove_visibility(void)
index d048630..4bd2ecf 100644 (file)
@@ -231,6 +231,10 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
         * because it's editable. */
 
        fp_pos = ftell(fp);
+       if (fp_pos < 0) {
+               perror("ftell");
+               return -1;
+       }
        tmp_msginfo = procheader_parse_stream(fp, flags, TRUE, FALSE);
        fseek(fp, fp_pos, SEEK_SET);
 
index 31708d6..ae6de82 100644 (file)
@@ -693,7 +693,12 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                        END_TIMING();
                        return;
                }
-               fseek(fp, mimeinfo->offset, SEEK_SET);
+               if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) {
+                       FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
+                       fclose(fp);
+                       END_TIMING();
+                       return;
+               }
                headers = textview_scan_header(textview, fp);
                if (headers) {
                        if (charcount > 0)
@@ -1075,8 +1080,10 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                filename = procmime_get_tmp_file_name(mimeinfo);
                if (procmime_get_part(filename, mimeinfo) == 0) {
                        tmpfp = g_fopen(filename, "rb");
-                       textview_show_ertf(textview, tmpfp, conv);
-                       fclose(tmpfp);
+                       if (tmpfp) {
+                               textview_show_ertf(textview, tmpfp, conv);
+                               fclose(tmpfp);
+                       }
                        claws_unlink(filename);
                }
                g_free(filename);
@@ -1155,7 +1162,11 @@ textview_default:
                        FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
                        return;
                }
-               fseek(tmpfp, mimeinfo->offset, SEEK_SET);
+               if (fseek(tmpfp, mimeinfo->offset, SEEK_SET) < 0) {
+                       FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
+                       fclose(tmpfp);
+                       return;
+               }
                debug_print("Viewing text content of type: %s (length: %d)\n", mimeinfo->subtype, mimeinfo->length);
                while (((i = ftell(tmpfp)) < mimeinfo->offset + mimeinfo->length) &&
                       (fgets(buf, sizeof(buf), tmpfp) != NULL)
@@ -2347,7 +2358,7 @@ void textview_scroll_max(TextView *textview, gboolean up)
 static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
                                 TextView *textview)
 {
-       GdkWindow *window;
+       GdkWindow *window = NULL;
        SummaryView *summaryview = NULL;
        MessageView *messageview = textview->messageview;
 
@@ -2393,15 +2404,17 @@ static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
                        summary_pass_key_press_event(summaryview, event);
                break;
        default:
-               window = gtk_widget_get_window(messageview->mainwin->window);
-               if (summaryview &&
-                   event->window != window) {
-                       GdkEventKey tmpev = *event;
-
-                       tmpev.window = window;
-                       KEY_PRESS_EVENT_STOP();
-                       gtk_widget_event(messageview->mainwin->window,
-                                        (GdkEvent *)&tmpev);
+               if (messageview->mainwin) {
+                       window = gtk_widget_get_window(messageview->mainwin->window);
+                       if (summaryview &&
+                           event->window != window) {
+                               GdkEventKey tmpev = *event;
+
+                               tmpev.window = window;
+                               KEY_PRESS_EVENT_STOP();
+                               gtk_widget_event(messageview->mainwin->window,
+                                                (GdkEvent *)&tmpev);
+                       }
                }
                break;
        }