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 <martin.vassor@hotmail.fr> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
0b46ad4faa
commit
0529b864b0
@ -309,7 +309,7 @@ app_arg(int add_line, struct date *day, long date, const char *fmt_apt,
|
|||||||
|
|
||||||
day_store_items(date, regex, 0);
|
day_store_items(date, regex, 0);
|
||||||
|
|
||||||
int n = day_item_count();
|
int n = day_item_count(0);
|
||||||
|
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
if (add_line)
|
if (add_line)
|
||||||
|
@ -713,7 +713,7 @@ unsigned day_chk_busy_slices(struct date, int, int *);
|
|||||||
struct day_item *day_cut_item(long, int);
|
struct day_item *day_cut_item(long, int);
|
||||||
int day_paste_item(struct day_item *, long);
|
int day_paste_item(struct day_item *, long);
|
||||||
struct day_item *day_get_item(int);
|
struct day_item *day_get_item(int);
|
||||||
unsigned day_item_count(void);
|
unsigned day_item_count(int);
|
||||||
void day_edit_note(struct day_item *, const char *);
|
void day_edit_note(struct day_item *, const char *);
|
||||||
void day_view_note(struct day_item *, const char *);
|
void day_view_note(struct day_item *, const char *);
|
||||||
void day_item_switch_notify(struct day_item *);
|
void day_item_switch_notify(struct day_item *);
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#include "calcurse.h"
|
#include "calcurse.h"
|
||||||
|
|
||||||
static vector_t day_items;
|
static vector_t day_items;
|
||||||
|
static unsigned day_items_nb = 0;
|
||||||
|
|
||||||
static void day_free(struct day_item *day)
|
static void day_free(struct day_item *day)
|
||||||
{
|
{
|
||||||
@ -359,6 +360,7 @@ day_store_items(long date, regex_t * regex, int include_captions)
|
|||||||
day_add_item(DAY_SEPARATOR, 0, p);
|
day_add_item(DAY_SEPARATOR, 0, p);
|
||||||
|
|
||||||
VECTOR_SORT(&day_items, day_cmp_start);
|
VECTOR_SORT(&day_items, day_cmp_start);
|
||||||
|
day_items_nb = events + apts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -682,9 +684,9 @@ struct day_item *day_get_item(int item_number)
|
|||||||
return VECTOR_NTH(&day_items, item_number);
|
return VECTOR_NTH(&day_items, item_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned day_item_count(void)
|
unsigned day_item_count(int include_captions)
|
||||||
{
|
{
|
||||||
return VECTOR_COUNT(&day_items);
|
return (include_captions ? VECTOR_COUNT(&day_items) : day_items_nb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Attach a note to an appointment or event. */
|
/* Attach a note to an appointment or event. */
|
||||||
|
20
src/ui-day.c
20
src/ui-day.c
@ -298,7 +298,7 @@ void ui_day_item_edit(void)
|
|||||||
struct apoint *a;
|
struct apoint *a;
|
||||||
int need_check_notify = 0;
|
int need_check_notify = 0;
|
||||||
|
|
||||||
if (day_item_count() <= 0)
|
if (day_item_count(0) <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct day_item *p = day_get_item(listbox_get_sel(&lb_apt));
|
struct day_item *p = day_get_item(listbox_get_sel(&lb_apt));
|
||||||
@ -412,7 +412,7 @@ void ui_day_item_pipe(void)
|
|||||||
int pid;
|
int pid;
|
||||||
FILE *fpout;
|
FILE *fpout;
|
||||||
|
|
||||||
if (day_item_count() <= 0)
|
if (day_item_count(0) <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct day_item *p = day_get_item(listbox_get_sel(&lb_apt));
|
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;
|
const int nb_note_choices = 2;
|
||||||
long date = ui_calendar_get_slctd_day_sec();
|
long date = ui_calendar_get_slctd_day_sec();
|
||||||
|
|
||||||
if (day_item_count() <= 0)
|
if (day_item_count(0) <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct day_item *p = day_get_item(listbox_get_sel(&lb_apt));
|
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;
|
struct recur_apoint *ra;
|
||||||
long until, date;
|
long until, date;
|
||||||
|
|
||||||
if (day_item_count() <= 0)
|
if (day_item_count(0) <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
item_nb = listbox_get_sel(&lb_apt);
|
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. */
|
/* Copy an item, so that it can be pasted somewhere else later. */
|
||||||
void ui_day_item_copy(unsigned reg)
|
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;
|
return;
|
||||||
|
|
||||||
struct day_item *item = day_get_item(listbox_get_sel(&lb_apt));
|
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)
|
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)
|
void ui_day_sel_reset(void)
|
||||||
@ -889,7 +889,7 @@ void ui_day_update_panel(int which_pan)
|
|||||||
|
|
||||||
void ui_day_popup_item(void)
|
void ui_day_popup_item(void)
|
||||||
{
|
{
|
||||||
if (day_item_count() <= 0)
|
if (day_item_count(0) <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct day_item *item = day_get_item(listbox_get_sel(&lb_apt));
|
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)
|
void ui_day_flag(void)
|
||||||
{
|
{
|
||||||
if (day_item_count() <= 0)
|
if (day_item_count(0) <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct day_item *item = day_get_item(listbox_get_sel(&lb_apt));
|
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)
|
void ui_day_view_note(void)
|
||||||
{
|
{
|
||||||
if (day_item_count() <= 0)
|
if (day_item_count(0) <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct day_item *item = day_get_item(listbox_get_sel(&lb_apt));
|
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)
|
void ui_day_edit_note(void)
|
||||||
{
|
{
|
||||||
if (day_item_count() <= 0)
|
if (day_item_count(0) <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct day_item *item = day_get_item(listbox_get_sel(&lb_apt));
|
struct day_item *item = day_get_item(listbox_get_sel(&lb_apt));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user