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>
This commit is contained in:
Lukas Fleischer 2014-07-28 11:54:03 +02:00
parent a366b5c2ba
commit 6ca2535f5e

View File

@ -488,30 +488,25 @@ static long ical_datetime2long(char *datestr, ical_vevent_e * type)
static long ical_durtime2long(char *timestr) static long ical_durtime2long(char *timestr)
{ {
long timelong;
char *p; char *p;
unsigned hour = 0, min = 0, sec = 0;
if ((p = strchr(timestr, 'T')) == NULL) { if ((p = strchr(timestr, 'T')) == NULL)
timelong = 0; return 0;
} else {
int nbmatch;
struct {
unsigned hour, min, sec;
} time;
p++; p++;
memset(&time, 0, sizeof time); if (strchr(p, 'H')) {
nbmatch = if (sscanf(p, "%uH%uM%uS", &hour, &min, &sec) != 3)
sscanf(p, "%uH%uM%uS", &time.hour, &time.min, return 0;
&time.sec); } else if (strchr(p, 'M')) {
if (nbmatch < 1 || nbmatch > 3) if (sscanf(p, "%uM%uS", &min, &sec) != 2)
timelong = 0; return 0;
else } else if (strchr(p, 'S')) {
timelong = if (sscanf(p, "%uS", &sec) != 1)
time.hour * HOURINSEC + time.min * MININSEC + return 0;
time.sec;
} }
return timelong;
return hour * HOURINSEC + min * MININSEC + sec;
} }
/* /*