RSSyl: Fix some more issues reported by Coverity.
authorAndrej Kacian <andrej@kacian.sk>
Sun, 29 Jun 2014 19:39:54 +0000 (21:39 +0200)
committerAndrej Kacian <andrej@kacian.sk>
Mon, 30 Jun 2014 19:04:15 +0000 (21:04 +0200)
src/plugins/rssyl/libfeed/feed.h
src/plugins/rssyl/libfeed/parser.c
src/plugins/rssyl/opml_export.c
src/plugins/rssyl/opml_import.c
src/plugins/rssyl/rssyl.c
src/plugins/rssyl/rssyl_add_item.c
src/plugins/rssyl/rssyl_deleted.c

index 5960133..15ce456 100644 (file)
@@ -107,7 +107,7 @@ gboolean feed_insert_item(Feed *feed, FeedItem *item, gint pos);
 
 guint feed_update(Feed *feed, time_t last_update);
 
-#define FILL(n)                { g_free(n); n = g_strdup(text); } while(0);
+#define FILL(n)                do { g_free(n); n = g_strdup(text); } while(0);
 
 #include "feeditem.h"
 
index 1ebc412..bb0bb0d 100644 (file)
@@ -164,7 +164,7 @@ gchar *feed_parser_get_attribute_value(const gchar **attr, const gchar *name)
 {
        guint i;
 
-       if( attr == NULL && name == NULL )
+       if( attr == NULL || name == NULL )
                return NULL;
 
        for( i = 0; attr[i] != NULL && attr[i+1] != NULL; i += 2 ) {
index 7ec9369..bc165ee 100644 (file)
@@ -125,8 +125,16 @@ void rssyl_opml_export(void)
        opmlfile = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, RSSYL_DIR,
                        G_DIR_SEPARATOR_S, RSSYL_OPML_FILE, NULL);
 
-       if( g_file_test(opmlfile, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR ) )
-               g_remove(opmlfile);
+       if( g_file_test(opmlfile, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR ) ) {
+               if (g_remove(opmlfile) != 0) {
+                       log_warning(LOG_PROTOCOL,
+                                       _("RSSyl: Couldn't delete old OPML file '%s': %s\n"),
+                                       opmlfile, g_strerror(errno));
+                       debug_print("RSSyl: couldn't delete old file '%s'\n", opmlfile);
+                       g_free(opmlfile);
+                       return;
+               }
+       }
        
        if( (f = g_fopen(opmlfile, "w")) == NULL ) {
                log_warning(LOG_PROTOCOL,
index 2a34f5d..737dfbe 100644 (file)
@@ -104,7 +104,12 @@ void rssyl_opml_import_func(gchar *title, gchar *url, gint depth, gpointer data)
                new_item = rssyl_feed_subscribe_new((FolderItem *)ctx->current->data,
                                url, TRUE);
                /* ...and rename it if needed */
-               if (new_item != NULL && strcmp(title, new_item->name))
-                       folder_item_rename(new_item, title);
+               if (new_item != NULL && strcmp(title, new_item->name)) {
+                       if (folder_item_rename(new_item, title) < 0) {
+                               alertpanel_error(_("Error while subscribing feed\n"
+                                                       "%s\n\nFolder name '%s' is not allowed."),
+                                               url, title);
+                       }
+               }
        }
 }
index 2c5a634..c87fde9 100644 (file)
@@ -641,7 +641,7 @@ static gint rssyl_get_num_list(Folder *folder, FolderItem *item,
 
        closedir(dp);
 
-       debug_print("Rssyl: get_num_list: returning %d\n", nummsgs);
+       debug_print("RSSyl: get_num_list: returning %d\n", nummsgs);
 
        return nummsgs;
 }
index 50a5102..1dc3e78 100644 (file)
@@ -130,14 +130,14 @@ static gint rssyl_cb_feed_compare(const FeedItem *a, const FeedItem *b)
                        return 0;
                else
                        return 1;
+       }
 
-               /* ... and as a last resort, if there is no title, item texts. */
-               if( no_title && a->text && b->text ) {
-                       if( !strcmp(a->text, b->text) )
-                               return 0;
-                       else
-                               return 1;
-               }
+       /* ... and as a last resort, if there is no title, item texts. */
+       if( no_title && a->text && b->text ) {
+               if( !strcmp(a->text, b->text) )
+                       return 0;
+               else
+                       return 1;
        }
 
        /* We don't know this item. */
@@ -269,7 +269,7 @@ void rssyl_add_item(RFolderItem *ritem, FeedItem *feed_item)
        MsgPermFlags oldperm_flags = 0;
        MsgInfo *msginfo;
        FILE *f;
-       gint fd, d, dif;
+       gint fd, d, dif, errno = 0;
        time_t tmpd;
        gchar *meta_charset = NULL;
        gchar *baseurl = NULL;
@@ -349,7 +349,10 @@ void rssyl_add_item(RFolderItem *ritem, FeedItem *feed_item)
                oldperm_flags = msginfo->flags.perm_flags;
 
                ritem->items = g_slist_remove(ritem->items, old_item);
-               g_remove(ctx->path);
+               if (g_unlink(ctx->path) != 0) {
+                       debug_print("RSSyl: Error, could not delete file '%s': %s\n",
+                                       ctx->path, g_strerror(errno));
+               }
 
                g_free(ctx->path);
                feed_item_free(old_item);
index d77c0b0..01cb0da 100644 (file)
@@ -170,20 +170,25 @@ static void rssyl_deleted_store_internal(GSList *deleted_items, const gchar *del
 {
        FILE *f;
 
-       if (g_file_test(deleted_file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))
-               g_remove(deleted_file);
+       if (g_file_test(deleted_file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
+               if (g_remove(deleted_file) != 0) {
+                       debug_print("RSSyl: Oops, couldn't delete '%s', bailing out\n",
+                                       deleted_file);
+                       return;
+               }
+       }
 
        if (g_slist_length(deleted_items) == 0)
                return;
 
        if ((f = g_fopen(deleted_file, "w")) == NULL) {
-               debug_print("RSSyl: Couldn't open '%s', ignoring.\n", deleted_file);
+               debug_print("RSSyl: Couldn't open '%s', bailing out.\n", deleted_file);
                return;
        }
 
        g_slist_foreach(deleted_items, (GFunc)_store_one_deleted_item,
                        (gpointer)f);
-       
+
        fclose(f);
        debug_print("RSSyl: written and closed deletion file\n");
 }