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 <r...@redhat.com>

Signed-off-by: Gleb Natapov<g...@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.



Reply via email to