From 1ccfd37f5513ed29a61325a81944386da4e2a737 Mon Sep 17 00:00:00 2001 From: katherine Date: Tue, 7 Jan 2020 14:51:09 -0700 Subject: more efficient entry checking it's a mess, but should work --- src/calendar.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/calendar.c') diff --git a/src/calendar.c b/src/calendar.c index bcf06f6..b852b1c 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -146,7 +146,7 @@ static struct entry_interval_s sub_get_interval(struct state_s *s) return iv; } - if (l > INT_MAX) { + if (l > INT_MAX - 365) { ERRP("time interval too large"); s->err_flag = true; return iv; @@ -229,7 +229,7 @@ static time_t sub_get_date(struct state_s *s) int i; char c; time_t rt = 0; - struct tm tmp; + struct tm ttmp; struct tm t = { .tm_year = 2000, .tm_mday = 1, @@ -346,7 +346,7 @@ skip_num: } validate: - tmp = t; + ttmp = t; /* NOTE: timegm is non-POSIX, but commonplace */ if (s->cur_local) @@ -359,13 +359,18 @@ validate: s->err_flag = true; } + if (s->cur_local) + t = *localtime(&rt); + else + t = *gmtime(&rt); + if ( - tmp.tm_year != t.tm_year || - tmp.tm_mon != t.tm_mon || - tmp.tm_mday != t.tm_mday || - tmp.tm_hour != t.tm_hour || - tmp.tm_min != t.tm_min || - tmp.tm_sec != t.tm_sec + ttmp.tm_year != t.tm_year || + ttmp.tm_mon != t.tm_mon || + ttmp.tm_mday != t.tm_mday || + ttmp.tm_hour != t.tm_hour || + ttmp.tm_min != t.tm_min || + ttmp.tm_sec != t.tm_sec ) { ERRP("invalid date"); s->err_flag = true; -- cgit v1.2.3