From e6e87516f569c2344f760287aec66f70da856c6d Mon Sep 17 00:00:00 2001 From: Mike Gorchak Date: Mon, 25 Feb 2013 23:51:16 +0200 Subject: [PATCH 1/2] date.c: fix unsigned time_t comparison tm_to_time_t() returns (time_t)-1 when it sees an error. On platforms with unsigned time_t, this value will be larger than any valid timestamp and will break the "Is this older than 10 days in the future?" check. Signed-off-by: Mike Gorchak Signed-off-by: Junio C Hamano --- date.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/date.c b/date.c index 57331ed406..1ac28e5e7b 100644 --- a/date.c +++ b/date.c @@ -383,7 +383,7 @@ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now, * sense to specify timestamp way into the future. Make * sure it is not later than ten days from now... */ - if (now + 10*24*3600 < specified) + if ((specified != -1) && (now + 10*24*3600 < specified)) return 0; tm->tm_mon = r->tm_mon; tm->tm_mday = r->tm_mday; From e1033da6af80b77d720ba7df9b8d3439666582e4 Mon Sep 17 00:00:00 2001 From: Mike Gorchak Date: Mon, 25 Feb 2013 23:53:40 +0200 Subject: [PATCH 2/2] Fix time offset calculation in case of unsigned time_t Fix time offset calculation expression in case if time_t is unsigned. This code works fine for signed and unsigned time_t. Signed-off-by: Mike Gorchak Signed-off-by: Junio C Hamano --- date.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/date.c b/date.c index 1ac28e5e7b..df20d0ba1d 100644 --- a/date.c +++ b/date.c @@ -694,8 +694,14 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset) /* mktime uses local timezone */ *timestamp = tm_to_time_t(&tm); - if (*offset == -1) - *offset = ((time_t)*timestamp - mktime(&tm)) / 60; + if (*offset == -1) { + time_t temp_time = mktime(&tm); + if ((time_t)*timestamp > temp_time) { + *offset = ((time_t)*timestamp - temp_time) / 60; + } else { + *offset = -(int)((temp_time - (time_t)*timestamp) / 60); + } + } if (*timestamp == -1) return -1;