git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] parse_date_basic(): let the system handle DST conversion

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Apr 15, 2015, 17:23 UTC
Message-ID
<CAPig+cSC8RZJ-+uP=ZExVH2ZyexfQmLjzdjoBA7yuWkdYE4EGQ@mail.gmail.com>
In-Reply-To
<xmqq618xmka9.fsf_-_@gitster.dls.corp.google.com>
On Wed, Apr 15, 2015 at 12:24 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 12 quoted lines
> The function parses the input to compute the broken-down time in
> "struct tm", and the GMT timezone offset.  If the timezone offset
> does not exist in the input, the broken-down time is turned into the
> number of seconds since epoch both in the current timezone and in
> GMT and the offset is computed as their difference.
>
> However, we forgot to make sure tm.tm_isdst is set to -1 (i.e. let
> the system figure out if DST is in effect in the current timezone
> when turning the broken-down time to the number of seconds since
> epoch); it is done so at the beginning of the function, but a call
> to match_digit() in the function can lead to a call to gmtime_r() to
> clobber the field.
Thanks for composing the commit message and turning this into a proper patch.
> Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> Diagnosed-by: Eric Sunshine <sunshine@sunshineco.com>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
For what it's worth:
Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>
Show 23 quoted lines
> ---
>  date.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/date.c b/date.c
> index 01fd73f..8ad6cef 100644
> --- a/date.c
> +++ b/date.c
> @@ -700,7 +700,11 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
>                 return -1;
>
>         if (*offset == -1) {
> -               time_t temp_time = mktime(&tm);
> +               time_t temp_time;
> +
> +               /* gmtime_r() in match_digit() may have clobbered it */
> +               tm.tm_isdst = -1;
> +               temp_time = mktime(&tm);
>                 if ((time_t)*timestamp > temp_time) {
>                         *offset = ((time_t)*timestamp - temp_time) / 60;
>                 } else {
> --
> 2.4.0-rc2-165-g862640d
Previous: Junio C HamanoNext: Linus Torvalds
Message 7 of 10 in “Odd broken "--date=now" behavior in current git”
  1. Linus TorvaldsApr 15, 2015
  2. Junio C HamanoApr 15, 2015
  3. Eric SunshineApr 15, 2015
  4. Junio C HamanoApr 15, 2015
  5. 1/2 parse_date_basic(): return early when given a bogus timestampJunio C Hamano, Apr 15, 2015
  6. 2/2 parse_date_basic(): let the system handle DST conversionJunio C Hamano, Apr 15, 2015
  7. Eric SunshineApr 15, 2015
  8. Linus TorvaldsApr 15, 2015
  9. Junio C HamanoApr 15, 2015
  10. Peter KreftingApr 15, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.