Skip to content

Commit

Permalink
parse_date_basic(): return early when given a bogus timestamp
Browse files Browse the repository at this point in the history
When the input does not have GMT timezone offset, the code computes
it by computing the local and GMT time for the given timestamp. But
there is no point doing so if the given timestamp is known to be a
bogus one.

Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
gitster committed Apr 15, 2015
1 parent 282616c commit 7fcec48
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions date.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,9 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)

/* mktime uses local timezone */
*timestamp = tm_to_time_t(&tm);
if (*timestamp == -1)
return -1;

if (*offset == -1) {
time_t temp_time = mktime(&tm);
if ((time_t)*timestamp > temp_time) {
Expand All @@ -705,9 +708,6 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
}
}

if (*timestamp == -1)
return -1;

if (!tm_gmt)
*timestamp -= *offset * 60;
return 0; /* success */
Expand Down

0 comments on commit 7fcec48

Please sign in to comment.