From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52115) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WiTLX-0000RZ-A2 for qemu-devel@nongnu.org; Thu, 08 May 2014 14:47:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WiTLU-0006Fm-PN for qemu-devel@nongnu.org; Thu, 08 May 2014 14:47:07 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:48064) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WiTLU-0006Dw-JP for qemu-devel@nongnu.org; Thu, 08 May 2014 14:47:04 -0400 From: Peter Maydell Date: Thu, 8 May 2014 19:46:54 +0100 Message-Id: <1399574818-19349-5-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1399574818-19349-1-git-send-email-peter.maydell@linaro.org> References: <1399574818-19349-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PATCH 4/8] hw/arm/omap1: Avoid unintended sign extension writing omap_rtc YEARS_REG List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Crosthwaite , patches@linaro.org When writing to the YEARS_REG register, if the year value is 99 then the multiplication by 31536000 will overflow into the sign bit of a 32 bit value and then be erroneously sign-extended if time_t is 64 bits. Add a cast to avoid this. Signed-off-by: Peter Maydell --- hw/arm/omap1.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/arm/omap1.c b/hw/arm/omap1.c index b433748..b28e052 100644 --- a/hw/arm/omap1.c +++ b/hw/arm/omap1.c @@ -2709,8 +2709,8 @@ static void omap_rtc_write(void *opaque, hwaddr addr, s->ti += ti[1]; } else { /* A less accurate version */ - s->ti -= (s->current_tm.tm_year % 100) * 31536000; - s->ti += from_bcd(value) * 31536000; + s->ti -= (time_t)(s->current_tm.tm_year % 100) * 31536000; + s->ti += (time_t)from_bcd(value) * 31536000; } return; -- 1.9.2