From patchwork Sun Nov 6 16:00:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 123934 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6B799B6F67 for ; Mon, 7 Nov 2011 03:00:37 +1100 (EST) Received: from localhost ([::1]:34412 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RN597-0007kh-FN for incoming@patchwork.ozlabs.org; Sun, 06 Nov 2011 11:00:33 -0500 Received: from eggs.gnu.org ([140.186.70.92]:49466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RN591-0007kc-R3 for qemu-devel@nongnu.org; Sun, 06 Nov 2011 11:00:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RN590-0004Re-SL for qemu-devel@nongnu.org; Sun, 06 Nov 2011 11:00:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:9116) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RN590-0004RY-LL for qemu-devel@nongnu.org; Sun, 06 Nov 2011 11:00:26 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pA6G0OR9002206 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 6 Nov 2011 11:00:25 -0500 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pA6G0NJv030686 for ; Sun, 6 Nov 2011 11:00:24 -0500 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id D2F7C133E89; Sun, 6 Nov 2011 18:00:22 +0200 (IST) Date: Sun, 6 Nov 2011 18:00:22 +0200 From: Gleb Natapov To: qemu-devel@nongnu.org Message-ID: <20111106160022.GF3225@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] qemu_timedate_diff() shouldn't modify its argument. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. Signed-off-by: Gleb Natapov Acked-by: Rik van Riel Acked-by: Ronen Hod --- Gleb. 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;