summaryrefslogtreecommitdiff
path: root/src/day.c
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2014-06-24 23:45:02 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2014-06-25 12:35:43 +0200
commit0529b864b0b2ababd799ee18faf486dbcce68b97 (patch)
treee2eb2cc780396a8065221d19a29d756d5cd2bcb7 /src/day.c
parent0b46ad4faaee1ce982a64413b57406e43cb83e88 (diff)
downloadcalcurse-0529b864b0b2ababd799ee18faf486dbcce68b97.zip
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>
Diffstat (limited to 'src/day.c')
-rw-r--r--src/day.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/day.c b/src/day.c
index 15daa41..5b5a3e3 100644
--- a/src/day.c
+++ b/src/day.c
@@ -43,6 +43,7 @@
#include "calcurse.h"
static vector_t day_items;
+static unsigned day_items_nb = 0;
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);
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);
}
-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. */