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 59601337b874b1ae741f74f591d56da3fdf748f7..15ce4567d2c28523939cd4e933d38d4b38e224f8 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 1ebc412025d7805abc51972a0be936158b58946a..bb0bb0d2e965ee7a87ead79adaeddfa3934dc4da 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 7ec9369d6f560a2375f3d2829f2b7ab4f182ebae..bc165eeabad6130bbed51897b1818155b27fa6db 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 2a34f5d77f3c24445b20472c59ea8b7c6d8e78c7..737dfbe0eecc5bc457ad2485554c49c64f5774c8 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 2c5a634dc880158d7ca01189be2284e0585463b9..c87fde95f137bf15d1ad225fe62c8e7724023b70 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 50a5102d4ea8c2c4d8a13dddf5dcb0c4f5d96e85..1dc3e78ac3eb0ffc634262354ad3e17b858f7897 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 d77c0b00cf7246174bf66e7024e91f06f3206230..01cb0da41b8758836fbcf2cdb1a40c995fcbef21 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");
 }