Coverity fixes
authorColin Leroy <colin@colino.net>
Tue, 10 Jun 2014 14:11:10 +0000 (16:11 +0200)
committerColin Leroy <colin@colino.net>
Tue, 10 Jun 2014 14:11:10 +0000 (16:11 +0200)
src/plugins/vcalendar/month-view.c
src/plugins/vcalendar/vcal_folder.c
src/plugins/vcalendar/vcal_manager.c
src/plugins/vcalendar/vcal_manager.h
src/plugins/vcalendar/vcal_meeting_gtk.c
src/plugins/vcalendar/vcalendar.c

index ba59a2d..e95ffa0 100644 (file)
@@ -152,6 +152,11 @@ static char *orage_tm_date_to_i18_date(struct tm *tm_date)
     t.tm_mday = tm_date->tm_mday;
     t.tm_mon = tm_date->tm_mon - 1;
     t.tm_year = tm_date->tm_year - 1900;
+    t.tm_sec = 0;
+    t.tm_min = 0;
+    t.tm_hour = 0;
+    t.tm_wday = 0;
+    t.tm_yday = 0;
     if (strftime(i18_date, 32, "%x", &t) == 0)
         g_error("Orage: orage_tm_date_to_i18_date too long string in strftime");
     return(i18_date);
@@ -548,7 +553,7 @@ static void app_rows(month_win *mw, FolderItem *item)
 {
    GSList *events = vcal_get_events_list(item);
    GSList *cur = NULL;
-   int days = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mw->day_spin));
+   int days = 7;
    for (cur = events; cur ; cur = cur->next) {
        VCalEvent *event = (VCalEvent *) (cur->data);
        add_row(mw, event, days);
@@ -841,7 +846,7 @@ static void build_month_view_table(month_win *mw)
                t = 1;
 #endif
     localtime_r(&t, &tm_today);
-    days = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mw->day_spin));
+    days = 7;
     /****** header of day table = days columns ******/
     mw->scroll_win_h = gtk_scrolled_window_new(NULL, NULL);
     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(mw->scroll_win_h)
index a376914..76928f5 100644 (file)
@@ -1844,6 +1844,19 @@ static void update_subscription_finish(const gchar *uri, gchar *feed, gboolean v
                        }
                }
                item = folder_create_folder(root->node->data, title);
+               if (!item) {
+                       if (verbose && manual_update) {
+                               alertpanel_error(_("Could not create directory %s"),
+                                       title);
+                       } else  {
+                               log_error(LOG_PROTOCOL, _("Could not create directory %s"),
+                                       title);
+                       }
+                       g_free(feed);
+                       g_free(title);
+                       main_window_cursor_normal(mainwindow_get_mainwindow());
+                       return;
+               }
                debug_print("item done %s\n", title);
                ((VCalFolderItem *)item)->uri = g_strdup(uri);
                ((VCalFolderItem *)item)->feed = feed;
@@ -2059,6 +2072,9 @@ static void set_view_cb(GtkAction *gaction, GtkRadioAction *current, gpointer da
        oitem = gtk_cmctree_node_get_row_data(ctree, folderview->opened);
        item = gtk_cmctree_node_get_row_data(ctree, folderview->selected);
 
+       if (!item)
+               return;
+
        if (((VCalFolderItem *)(item))->use_cal_view == action)
                return;
        debug_print("set view %d\n", action);
@@ -2171,7 +2187,7 @@ VCalEvent *vcal_get_event_from_ical(const gchar *ical, const gchar *charset)
        gchar *recur = NULL;
        int sequence = 0;
        enum icalproperty_method method = ICAL_METHOD_REQUEST;
-       enum icalproperty_kind type = ICAL_VEVENT_COMPONENT;
+       enum icalcomponent_kind type = ICAL_VEVENT_COMPONENT;
        GSList *attendees = NULL;
        
        if (comp == NULL) {
index 7ae557e..7a4cef2 100644 (file)
@@ -638,8 +638,8 @@ gchar *vcal_manager_dateevent_dump(const gchar *uid, FolderItem *item)
        if (str_write_to_file(body, tmpfile) < 0) {
                g_free(tmpfile);
                tmpfile = NULL;
-       }
-       chmod(tmpfile, S_IRUSR|S_IWUSR);
+       } else
+               chmod(tmpfile, S_IRUSR|S_IWUSR);
 
        g_free(body);
        g_free(headers);
@@ -751,8 +751,8 @@ gchar *vcal_manager_icalevent_dump(icalcomponent *event, gchar *orga, icalcompon
        if (str_write_to_file(body, tmpfile) < 0) {
                g_free(tmpfile);
                tmpfile = NULL;
-       }
-       chmod(tmpfile, S_IRUSR|S_IWUSR);
+       } else
+               chmod(tmpfile, S_IRUSR|S_IWUSR);
 
        g_strfreev(lines);
        g_free(body);
@@ -776,7 +776,7 @@ VCalEvent * vcal_manager_new_event  (const gchar    *uid,
                                         const gchar    *url,
                                         enum icalproperty_method method,
                                         gint            sequence,
-                                        enum icalproperty_kind type)
+                                        enum icalcomponent_kind type)
 {
        VCalEvent *event = g_new0(VCalEvent, 1);
 
@@ -953,14 +953,20 @@ void vcal_manager_save_event (VCalEvent *event, gboolean export_after)
        path = vcal_manager_get_event_file(event->uid);
                                        
        if ((pfile = prefs_write_open(path)) == NULL) {
-               make_dir(vcal_manager_get_event_path());
+               gchar *dir_path = vcal_manager_get_event_path();
+               if (!is_dir_exist(dir_path) && make_dir(vcal_manager_get_event_path()) != 0) {
+                       g_free(dir_path);
+                       g_free(path);
+                       return;
+               }
+               g_free(dir_path);
                if ((pfile = prefs_write_open(path)) == NULL) {
-                       free(path);
+                       g_free(path);
                        return;
                }
        }
        
-       free(path);
+       g_free(path);
        xml_file_put_xml_decl(pfile->fp);
        xml_write_tree(rootnode, pfile->fp);
        xml_free_tree(rootnode);
@@ -1174,6 +1180,8 @@ static gchar *write_headers(PrefsAccount  *account,
        gchar msgid[128];       
        gchar *calmsgid = NULL;
 
+       cm_return_val_if_fail(account != NULL, NULL);
+
        memset(date, 0, sizeof(date));
        
        if (is_pseudo_display) {
index 4545cd6..9a4b43f 100644 (file)
@@ -85,7 +85,7 @@ VCalEvent *vcal_manager_new_event     (const gchar    *uid,
                                         const gchar    *url,
                                         enum icalproperty_method method,
                                         gint            sequence,
-                                        enum icalproperty_kind type);
+                                        enum icalcomponent_kind type);
                                         
 void vcal_manager_free_event (VCalEvent *event);
 void vcal_manager_save_event (VCalEvent *event, gboolean export_after);
index 5dd32ad..eae703e 100644 (file)
@@ -362,7 +362,7 @@ static gchar *get_organizer(VCalMeeting *meet)
                cur = cur->next;
                i++;
        }
-       if (cur)
+       if (cur && cur->data)
                return g_strdup(((PrefsAccount *)(cur->data))->address);
        else
                return g_strdup("");
@@ -378,7 +378,7 @@ static gchar *get_organizer_name(VCalMeeting *meet)
                cur = cur->next;
                i++;
        }
-       if (cur)
+       if (cur && cur->data)
                return g_strdup(((PrefsAccount *)(cur->data))->name);
        else
                return g_strdup("");
@@ -1247,10 +1247,17 @@ static gboolean send_meeting_cb(GtkButton *widget, gpointer data)
                gdk_window_set_cursor(meet->window->window, watch_cursor);
 
        organizer       = get_organizer(meet);
-       organizer_name  = get_organizer_name(meet);
        account         = account_find_from_address(organizer, FALSE);
 
-       if (account && account->set_domain && account->domain) {
+       if(account == NULL) {
+               debug_print("can't get account from address %s\n", organizer);
+               g_free(organizer);
+               return FALSE;
+       }
+
+       organizer_name  = get_organizer_name(meet);
+
+       if (account->set_domain && account->domain) {
                g_snprintf(buf, sizeof(buf), "%s", account->domain); 
        } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
                g_snprintf(buf, sizeof(buf), "%s", 
@@ -1943,12 +1950,11 @@ void multisync_export(void)
        icalcomponent *calendar = NULL;
        FILE *fp;
 
-       if (is_dir_exist(path))
-               remove_dir_recursive(path);
-       if (!is_dir_exist(path))
-               make_dir(path);
-       if (!is_dir_exist(path)) {
-               perror(path);
+       if (is_dir_exist(path) && remove_dir_recursive(path) < 0) {
+               g_free(path);
+               return;
+       }
+       if (make_dir(path) != 0) {
                g_free(path);
                return;
        }
index 263d542..bdfe503 100644 (file)
@@ -1321,8 +1321,11 @@ void vcalendar_init(void)
        gchar *directory = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                "vcalendar", NULL);
        START_TIMING("");
-       if (!is_dir_exist(directory))
-               make_dir (directory);
+       if (!is_dir_exist(directory) && make_dir (directory) != 0) {
+               g_free(directory);
+               return;
+       }
+
        g_free(directory);
 
        vcal_prefs_init();
@@ -1339,16 +1342,15 @@ void vcalendar_init(void)
                folder_scan_tree(folder, TRUE);
                END_TIMING();
        }
-       if (folder) {
-               if (!folder->inbox) {
-                       folder->klass->create_tree(folder);
-                       folder_scan_tree(folder, TRUE);
-               }
-               if (folder->klass->scan_required(folder, folder->inbox)) {
-                       START_TIMING("scanning folder");
-                       folder_item_scan(folder->inbox);
-                       END_TIMING();
-               }
+
+       if (!folder->inbox) {
+               folder->klass->create_tree(folder);
+               folder_scan_tree(folder, TRUE);
+       }
+       if (folder->klass->scan_required(folder, folder->inbox)) {
+               START_TIMING("scanning folder");
+               folder_item_scan(folder->inbox);
+               END_TIMING();
        }
        
        vcal_folder_gtk_init();