More Coverity fixes
authorColin Leroy <colin@colino.net>
Thu, 5 Jun 2014 20:37:12 +0000 (22:37 +0200)
committerColin Leroy <colin@colino.net>
Thu, 5 Jun 2014 20:37:12 +0000 (22:37 +0200)
src/imap.c
src/importldif.c
src/main.c
src/mainwindow.c
src/messageview.c

index 6813d9e53bc45ac1376998d276a939947513bb25..887071979cd22f74ee88479fbf343487211c0128 100644 (file)
@@ -1672,8 +1672,10 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
                return -1;
        }
        destdir = imap_get_real_path(session, IMAP_FOLDER(folder), dest->path, &ok);
-       if (is_fatal(ok))
+       if (is_fatal(ok)) {
+               g_free(destdir);
                return -1;
+       }
        statusbar_print_all(_("Adding messages..."));
        total = g_slist_length(file_list);
        for (cur = file_list; cur != NULL; cur = cur->next) {
@@ -1870,8 +1872,10 @@ static gint imap_do_copy_msgs(Folder *folder, FolderItem *dest,
 
        destdir = imap_get_real_path(session, IMAP_FOLDER(folder), dest->path, &ok);
 
-       if (is_fatal(ok))
+       if (is_fatal(ok)) {
+               g_free(destdir);
                return ok;
+       }
 
        seq_list = imap_get_lep_set_from_msglist(IMAP_FOLDER(folder), msglist);
        uid_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
@@ -2487,10 +2491,8 @@ static gint imap_do_remove_msgs(Folder *folder, FolderItem *dest,
        imap_scan_required(folder, dest);
 
        g_free(destdir);
-       if (ok == MAILIMAP_NO_ERROR)
-               return 0;
-       else
-               return -1;
+
+       return 0;
 }
 
 static gint imap_remove_msgs(Folder *folder, FolderItem *dest, 
@@ -2566,8 +2568,10 @@ static gint imap_scan_tree_real(Folder *folder, gboolean subs_only)
                strtailchomp(root_folder, '/');
                real_path = imap_get_real_path
                        (session, IMAP_FOLDER(folder), root_folder, &r);
-               if (is_fatal(r))
+               if (is_fatal(r)) {
+                       g_free(real_path);
                        return -1;
+               }
                debug_print("IMAP root directory: %s\n", real_path);
 
                /* check if root directory exist */
@@ -2872,6 +2876,7 @@ GList *imap_scan_subtree(Folder *folder, FolderItem *item, gboolean unsubs_only,
                        if (r) {
                                g_free(real_path);
                                statusbar_pop_all();
+                               g_free(tmp);
                                return NULL;
                        }
                        folder_item_destroy(cur_item);
@@ -3228,6 +3233,7 @@ static gint imap_rename_folder(Folder *folder, FolderItem *item,
 
        real_oldpath = imap_get_real_path(session, IMAP_FOLDER(folder), item->path, &ok);
        if (is_fatal(ok)) {
+               g_free(real_oldpath);
                return -1;
        }
 
@@ -3244,8 +3250,10 @@ static gint imap_rename_folder(Folder *folder, FolderItem *item,
        }
 
        separator = imap_get_path_separator(session, IMAP_FOLDER(folder), item->path, &ok);
-       if (is_fatal(ok))
+       if (is_fatal(ok)) {
+               g_free(real_oldpath);
                return -1;
+       }
        if (strchr(item->path, G_DIR_SEPARATOR)) {
                dirpath = g_path_get_dirname(item->path);
                newpath = g_strconcat(dirpath, G_DIR_SEPARATOR_S, name, NULL);
@@ -3342,9 +3350,10 @@ static gint imap_remove_folder_real(Folder *folder, FolderItem *item)
                return -1;
        }
        path = imap_get_real_path(session, IMAP_FOLDER(folder), item->path, &ok);
-       if (is_fatal(ok))
+       if (is_fatal(ok)) {
+               g_free(path);
                return -1;
-
+       }
        imap_threaded_subscribe(folder, path, FALSE);
 
        selected_folder = (session->mbox != NULL) &&
@@ -3626,15 +3635,12 @@ gchar imap_get_path_separator_for_item(FolderItem *item)
        if (!item)
                return '/';
        folder = item->folder;
-       
+
        if (!folder)
                return '/';
-       
+
        imap_folder = IMAP_FOLDER(folder);
-       
-       if (!imap_folder)
-               return '/';
-       
+
        debug_print("getting session...");
        session = imap_session_get(FOLDER(folder));
        result = imap_get_path_separator(session, imap_folder, item->path, &ok);
@@ -3830,8 +3836,10 @@ static gint imap_select(IMAPSession *session, IMAPFolder *folder,
        session->expunge = 0;
 
        real_path = imap_get_real_path(session, folder, path, &ok);
-       if (is_fatal(ok))
-               return ok;              
+       if (is_fatal(ok)) {
+               g_free(real_path);
+               return ok;      
+       }       
        g_slist_free(IMAP_FOLDER_ITEM(item)->ok_flags);
        IMAP_FOLDER_ITEM(item)->ok_flags = NULL;
        ok = imap_cmd_select(session, real_path,
index 3d2460c7ec7666d47b3f2318a2fd2f953e70d3f8..e8db5b64f12231e401a41c86ba05036b5e367657 100644 (file)
@@ -336,7 +336,8 @@ static gboolean imp_ldif_field_list_toggle(
                        gint y = event->y;
                        gint row, col;
 
-                       gtk_cmclist_get_selection_info( clist, x, y, &row, &col );
+                       if (!gtk_cmclist_get_selection_info( clist, x, y, &row, &col ))
+                               return FALSE;
                        if( col != FIELD_COL_SELECT ) return FALSE;
                        if( row > impldif_dlg.rowCount ) return FALSE;
 
index 37b26d5ccaade9fca3d265b8865000f5eb75ff2a..0202a2070450dcf18621d6f9d5eeca68b54f3d56 100644 (file)
@@ -2241,6 +2241,7 @@ static gint prohibit_duplicate_launch(void)
                ret = fd_open_unix(path);
 #if HAVE_FLOCK
                flock(lock_fd, LOCK_UN);
+               close(lock_fd);
                claws_unlink(socket_lock);
                g_free(socket_lock);
 #endif
@@ -2340,7 +2341,8 @@ static gint prohibit_duplicate_launch(void)
                }
                fd_write_all(uxsock, ".\n", 2);
                for (;;) {
-                       fd_gets(uxsock, buf, sizeof(buf));
+                       fd_gets(uxsock, buf, sizeof(buf) - 1);
+                       buf[sizeof(buf) - 1] = '\0';
                        if (!strncmp(buf, ".\n", 2)) break;
                        fputs(buf, stdout);
                }
@@ -2350,7 +2352,8 @@ static gint prohibit_duplicate_launch(void)
                gchar buf[BUFSIZ];
                fd_write(uxsock, "statistics\n", 11);
                for (;;) {
-                       fd_gets(uxsock, buf, sizeof(buf));
+                       fd_gets(uxsock, buf, sizeof(buf) - 1);
+                       buf[sizeof(buf) - 1] = '\0';
                        if (!strncmp(buf, ".\n", 2)) break;
                        fputs(buf, stdout);
                }
@@ -2369,7 +2372,8 @@ static gint prohibit_duplicate_launch(void)
                fd_write_all(uxsock, str, strlen(str));
                g_free(str);
                for (;;) {
-                       fd_gets(uxsock, buf, sizeof(buf));
+                       fd_gets(uxsock, buf, sizeof(buf) - 1);
+                       buf[sizeof(buf) - 1] = '\0';
                        if (!strncmp(buf, ".\n", 2)) break;
                        fputs(buf, stdout);
                }
@@ -2378,7 +2382,8 @@ static gint prohibit_duplicate_launch(void)
                gchar buf[BUFSIZ];
                fd_write_all(uxsock, "get_display\n", 12);
                memset(buf, 0, sizeof(buf));
-               fd_gets(uxsock, buf, sizeof(buf));
+               fd_gets(uxsock, buf, sizeof(buf) - 1);
+               buf[sizeof(buf) - 1] = '\0';
                if (strcmp2(buf, x_display)) {
                        g_print("Claws Mail is already running on display %s.\n",
                                buf);
@@ -2428,7 +2433,8 @@ static GPtrArray *get_folder_item_list(gint sock)
        GPtrArray *folders = NULL;
 
        for (;;) {
-               fd_gets(sock, buf, sizeof(buf));
+               fd_gets(sock, buf, sizeof(buf) - 1);
+               buf[sizeof(buf) - 1] = '\0';
                if (!strncmp(buf, ".\n", 2)) {
                        break;
                }
@@ -2456,7 +2462,11 @@ static void lock_socket_input_cb(gpointer data,
        gchar buf[BUFFSIZE];
 
        sock = fd_accept(source);
-       fd_gets(sock, buf, sizeof(buf));
+       if (sock < 0)
+               return;
+
+       fd_gets(sock, buf, sizeof(buf) - 1);
+       buf[sizeof(buf) - 1] = '\0';
 
        if (!strncmp(buf, "popup", 5)) {
                main_window_popup(mainwin);
@@ -2478,7 +2488,8 @@ static void lock_socket_input_cb(gpointer data,
                gchar *mailto;
 
                mailto = g_strdup(buf + strlen("compose_attach") + 1);
-               while (fd_gets(sock, buf, sizeof(buf)) > 0) {
+               while (fd_gets(sock, buf, sizeof(buf) - 1) > 0) {
+                       buf[sizeof(buf) - 1] = '\0';
                        strretchomp(buf);
                        if (!strcmp2(buf, "."))
                                break;
@@ -2594,8 +2605,9 @@ static void lock_socket_input_cb(gpointer data,
                folder_name = g_strdup(buf+7);
                strretchomp(folder_name);
 
-               if (fd_gets(sock, buf, sizeof(buf)) <= 0) 
+               if (fd_gets(sock, buf, sizeof(buf) - 1) <= 0) 
                        goto search_exit;
+               buf[sizeof(buf) - 1] = '\0';
 
                switch (toupper(buf[0])) {
                case 'S': searchType = ADVANCED_SEARCH_SUBJECT; break;
@@ -2606,22 +2618,24 @@ static void lock_socket_input_cb(gpointer data,
                case 'E': searchType = ADVANCED_SEARCH_EXTENDED; break;
                }
 
-               if (fd_gets(sock, buf, sizeof(buf)) <= 0) 
+               if (fd_gets(sock, buf, sizeof(buf) - 1) <= 0) 
                        goto search_exit;
 
+               buf[sizeof(buf) - 1] = '\0';
                request = g_strdup(buf);
                strretchomp(request);
 
                recursive = TRUE;
-               if (fd_gets(sock, buf, sizeof(buf)) > 0)
+               if (fd_gets(sock, buf, sizeof(buf) - 1) > 0)
                        recursive = buf[0] != '0';
 
+               buf[sizeof(buf) - 1] = '\0';
+
                debug_print("search: %s %i %s %i\n", folder_name, searchType, request, recursive);
 
-               if (folder_name)
-                       folderItem = folder_find_item_from_identifier(folder_name);
+               folderItem = folder_find_item_from_identifier(folder_name);
 
-               if (folder_name && folderItem == NULL) {
+               if (folderItem == NULL) {
                        debug_print("Unknown folder item : '%s', searching folder\n",folder_name);
                        Folder* folder = folder_find_from_path(folder_name);
                        if (folder != NULL)
index 62b380a40767341b0b654c12579d805823700fe0..46de25b6e6e9064b45e65a434d113a8b4a2da7f9 100644 (file)
@@ -1241,7 +1241,7 @@ static gint mainwin_tag_cmp_list(gconstpointer a, gconstpointer b)
                return tag_b == NULL ? 0:1;
        
        if (tag_b == NULL)
-               return tag_a == NULL ? 0:1;
+               return tag_a == 1;
  
        return g_utf8_collate(tag_a, tag_b);
 }
@@ -3301,7 +3301,7 @@ do { \
                cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Sort/Descending", FALSE);
        }
 
-       if (mainwin->messageview 
+       if (mainwin->messageview
        &&  mainwin->messageview->mimeview
        &&  mainwin->messageview->mimeview->textview)
                cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/AllHeaders",
index 2d9c6778f924853d8ef16097d9cedfe36084802c..3acacd274c32f08750b355056616ecc12946c696 100644 (file)
@@ -1208,11 +1208,12 @@ static void messageview_register_nav(MessageView *messageview)
 }
 
 gboolean messageview_nav_has_prev(MessageView *messageview) {
-       return messageview->trail != NULL &&  messageview->trail_pos > 0;
+       return messageview != NULL && messageview->trail != NULL
+               && messageview->trail_pos > 0;
 }
 
 gboolean messageview_nav_has_next(MessageView *messageview) {
-       if (!messageview->trail)
+       if (!messageview || !messageview->trail)
                return FALSE;
        
        return sc_g_list_bigger(messageview->trail, messageview->trail_pos + 1);