From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:47833) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RNgEX-0004lM-72 for qemu-devel@nongnu.org; Tue, 08 Nov 2011 02:36:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RNgEV-0003On-HQ for qemu-devel@nongnu.org; Tue, 08 Nov 2011 02:36:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39119) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RNgEV-0003OS-AW for qemu-devel@nongnu.org; Tue, 08 Nov 2011 02:36:35 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pA87aXOt010811 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 8 Nov 2011 02:36:33 -0500 Date: Tue, 8 Nov 2011 09:36:31 +0200 From: Gleb Natapov Message-ID: <20111108073631.GM3225@redhat.com> References: <20111106160022.GF3225@redhat.com> <4EB83C9D.3090004@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4EB83C9D.3090004@redhat.com> Subject: Re: [Qemu-devel] [PATCH] qemu_timedate_diff() shouldn't modify its argument. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Ronen Hod Cc: qemu-devel@nongnu.org On Mon, Nov 07, 2011 at 10:16:29PM +0200, Ronen Hod wrote: > 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. Don't know what do you mean here. The problem is definitely related to incorrect data about daylight saving time. > using tmp.tm_isdst = -1 sounds good, but why use a copy of tm? The Hmm, what is not clear about "qemu_timedate_diff() shouldn't modify its argument"? :) > only significant field that will change in the tm is the tm_isdst > itself that will be set to 0/1 (correctly). This is incorrect (read man), but event if it would breed a new kind of especially handsome ponies, if this is what caller wants it should call mktime() by itself and not be a side effect of some random function call. > > Acked-by: Ronen Hod > > >Signed-off-by: Gleb Natapov > >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. > > -- Gleb.