From 0529b864b0b2ababd799ee18faf486dbcce68b97 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Tue, 24 Jun 2014 23:45:02 +0200 Subject: Fix segmentation fault This adds some more accurate checks to avoid a segmentation fault that occurred when accessing a nonexistent item. Fixes GitHub issue #7. Reported-by: Bromind Signed-off-by: Lukas Fleischer --- src/ui-day.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/ui-day.c') diff --git a/src/ui-day.c b/src/ui-day.c index 8c34e77..d6be872 100644 --- a/src/ui-day.c +++ b/src/ui-day.c @@ -298,7 +298,7 @@ void ui_day_item_edit(void) struct apoint *a; int need_check_notify = 0; - if (day_item_count() <= 0) + if (day_item_count(0) <= 0) return; struct day_item *p = day_get_item(listbox_get_sel(&lb_apt)); @@ -412,7 +412,7 @@ void ui_day_item_pipe(void) int pid; FILE *fpout; - if (day_item_count() <= 0) + if (day_item_count(0) <= 0) return; struct day_item *p = day_get_item(listbox_get_sel(&lb_apt)); @@ -575,7 +575,7 @@ void ui_day_item_delete(unsigned reg) const int nb_note_choices = 2; long date = ui_calendar_get_slctd_day_sec(); - if (day_item_count() <= 0) + if (day_item_count(0) <= 0) return; struct day_item *p = day_get_item(listbox_get_sel(&lb_apt)); @@ -668,7 +668,7 @@ void ui_day_item_repeat(void) struct recur_apoint *ra; long until, date; - if (day_item_count() <= 0) + if (day_item_count(0) <= 0) return; item_nb = listbox_get_sel(&lb_apt); @@ -797,7 +797,7 @@ void ui_day_item_cut_free(unsigned reg) /* Copy an item, so that it can be pasted somewhere else later. */ void ui_day_item_copy(unsigned reg) { - if (day_item_count() <= 0 || reg == REG_BLACK_HOLE) + if (day_item_count(0) <= 0 || reg == REG_BLACK_HOLE) return; struct day_item *item = day_get_item(listbox_get_sel(&lb_apt)); @@ -821,7 +821,7 @@ void ui_day_item_paste(unsigned reg) void ui_day_load_items(void) { - listbox_load_items(&lb_apt, day_item_count()); + listbox_load_items(&lb_apt, day_item_count(1)); } void ui_day_sel_reset(void) @@ -889,7 +889,7 @@ void ui_day_update_panel(int which_pan) void ui_day_popup_item(void) { - if (day_item_count() <= 0) + if (day_item_count(0) <= 0) return; struct day_item *item = day_get_item(listbox_get_sel(&lb_apt)); @@ -898,7 +898,7 @@ void ui_day_popup_item(void) void ui_day_flag(void) { - if (day_item_count() <= 0) + if (day_item_count(0) <= 0) return; struct day_item *item = day_get_item(listbox_get_sel(&lb_apt)); @@ -907,7 +907,7 @@ void ui_day_flag(void) void ui_day_view_note(void) { - if (day_item_count() <= 0) + if (day_item_count(0) <= 0) return; struct day_item *item = day_get_item(listbox_get_sel(&lb_apt)); @@ -916,7 +916,7 @@ void ui_day_view_note(void) void ui_day_edit_note(void) { - if (day_item_count() <= 0) + if (day_item_count(0) <= 0) return; struct day_item *item = day_get_item(listbox_get_sel(&lb_apt)); -- cgit v1.2.3-54-g00ecf