qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Ronen Hod <rhod@redhat.com>
To: Gleb Natapov <gleb@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] qemu_timedate_diff() shouldn't modify its argument.
Date: Mon, 07 Nov 2011 22:16:29 +0200	[thread overview]
Message-ID: <4EB83C9D.3090004@redhat.com> (raw)
In-Reply-To: <20111106160022.GF3225@redhat.com>

On 11/06/2011 06:00 PM, Gleb Natapov wrote:
> The caller of qemu_timedate_diff() does not expect that tm it passes to
> the function will be modified, but mktime() is destructive and modifies
> its argument. Pass a copy of tm to it and set tm_isdst so that mktime()
> will not rely on it since its value may be outdated.

I believe that the original issue was not related to outdated data at 
the moment of the daylight saving time transition.
using tmp.tm_isdst = -1 sounds good, but why use a copy of tm? The only 
significant field that will change in the tm is the tm_isdst itself that 
will be set to 0/1 (correctly).

Acked-by: Ronen Hod <rhod@redhat.com>

> Signed-off-by: Gleb Natapov<gleb@redhat.com>
> diff --git a/vl.c b/vl.c
> index 624da0f..641629b 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -460,8 +460,11 @@ int qemu_timedate_diff(struct tm *tm)
>       if (rtc_date_offset == -1)
>           if (rtc_utc)
>               seconds = mktimegm(tm);
> -        else
> -            seconds = mktime(tm);
> +        else {
> +            struct tm tmp = *tm;
> +            tmp.tm_isdst = -1; /* use timezone to figure it out */
> +            seconds = mktime(&tmp);
> +	}
>       else
>           seconds = mktimegm(tm) + rtc_date_offset;
>
> --
> 			Gleb.
>

  parent reply	other threads:[~2011-11-07 20:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-06 16:00 [Qemu-devel] [PATCH] qemu_timedate_diff() shouldn't modify its argument Gleb Natapov
2011-11-07 19:09 ` Rik van Riel
2011-11-07 20:16 ` Ronen Hod [this message]
2011-11-08  7:36   ` Gleb Natapov
2011-11-08 17:24 ` Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4EB83C9D.3090004@redhat.com \
    --to=rhod@redhat.com \
    --cc=gleb@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).