More Coverity fixes
authorColin Leroy <colin@colino.net>
Thu, 5 Jun 2014 19:29:31 +0000 (21:29 +0200)
committerColin Leroy <colin@colino.net>
Thu, 5 Jun 2014 19:29:31 +0000 (21:29 +0200)
12 files changed:
src/compose.c
src/edittags.c
src/filtering.c
src/folder.c
src/folderview.c
src/grouplistdialog.c
src/gtk/gtkcmclist.c
src/gtk/gtkcmctree.c
src/gtk/gtkunit.c
src/gtk/gtkutils.c
src/gtk/prefswindow.c
src/gtk/quicksearch.c

index fa1e815..e1323f2 100644 (file)
@@ -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,
index dd74e13..a107c15 100644 (file)
@@ -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);
 }
index 1d8126f..ff6eece 100644 (file)
@@ -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 */
index 781b24c..2a8d862 100644 (file)
@@ -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)) {
index a52ce3f..e9b0943 100644 (file)
@@ -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);
index 83b0ea7..21ee8d1 100644 (file)
@@ -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;
 
index fe0c071..3a28036 100644 (file)
@@ -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;
index ca65ca8..f8d9541 100644 (file)
@@ -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);
index 61272dd..5652610 100644 (file)
@@ -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;
 }
index 08b0547..d547917 100644 (file)
@@ -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
index 57b1c57..0b407d3 100644 (file)
@@ -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
index f10948b..d595c44 100644 (file)
@@ -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 */