summaryrefslogtreecommitdiff
path: root/src/ical.c
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2014-07-28 11:54:03 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2014-07-28 12:43:00 +0200
commit6ca2535f5e35147b469fb4a9bde9148eed4aa01e (patch)
tree6b2945782fe8c153d07c86fa9a82d9c524901d8e /src/ical.c
parenta366b5c2baf0a014ac95a8e262b672e0b0f97c57 (diff)
downloadcalcurse-6ca2535f5e35147b469fb4a9bde9148eed4aa01e.zip
ical.c: Simplify and fix ical_durtime2long()
Correctly parse all types of durations. Before this change, durations without an hour or minute component were not parsed properly. Reported-by: HÃ¥kan Jerning <jerning@home.se> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src/ical.c')
-rw-r--r--src/ical.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/src/ical.c b/src/ical.c
index d953b0e..dda642a 100644
--- a/src/ical.c
+++ b/src/ical.c
@@ -488,30 +488,25 @@ static long ical_datetime2long(char *datestr, ical_vevent_e * type)
static long ical_durtime2long(char *timestr)
{
- long timelong;
char *p;
+ unsigned hour = 0, min = 0, sec = 0;
- if ((p = strchr(timestr, 'T')) == NULL) {
- timelong = 0;
- } else {
- int nbmatch;
- struct {
- unsigned hour, min, sec;
- } time;
+ if ((p = strchr(timestr, 'T')) == NULL)
+ return 0;
- p++;
- memset(&time, 0, sizeof time);
- nbmatch =
- sscanf(p, "%uH%uM%uS", &time.hour, &time.min,
- &time.sec);
- if (nbmatch < 1 || nbmatch > 3)
- timelong = 0;
- else
- timelong =
- time.hour * HOURINSEC + time.min * MININSEC +
- time.sec;
+ p++;
+ if (strchr(p, 'H')) {
+ if (sscanf(p, "%uH%uM%uS", &hour, &min, &sec) != 3)
+ return 0;
+ } else if (strchr(p, 'M')) {
+ if (sscanf(p, "%uM%uS", &min, &sec) != 2)
+ return 0;
+ } else if (strchr(p, 'S')) {
+ if (sscanf(p, "%uS", &sec) != 1)
+ return 0;
}
- return timelong;
+
+ return hour * HOURINSEC + min * MININSEC + sec;
}
/*