From patchwork Fri Oct 16 17:48:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 531497 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 079531402B2 for ; Sat, 17 Oct 2015 04:49:22 +1100 (AEDT) Received: from localhost ([::1]:55208 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn984-0000hl-4B for incoming@patchwork.ozlabs.org; Fri, 16 Oct 2015 13:49:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn97n-0000Q1-8j for qemu-devel@nongnu.org; Fri, 16 Oct 2015 13:49:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zn97m-0000wf-AM for qemu-devel@nongnu.org; Fri, 16 Oct 2015 13:49:03 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:35161) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn97m-0000wF-3h for qemu-devel@nongnu.org; Fri, 16 Oct 2015 13:49:02 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Zn97j-0003sP-2L; Fri, 16 Oct 2015 18:48:59 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 16 Oct 2015 18:48:59 +0100 Message-Id: <1445017739-14876-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Cc: John Snow , qemu-block@nongnu.org, patches@linaro.org Subject: [Qemu-devel] [PATCH] hw/ide/ahci.c: Fix shift left into sign bit 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 Avoid undefined behaviour from shifting left into the sign bit: hw/ide/ahci.c:551:36: runtime error: left shift of 255 by 24 places cannot be represented in type 'int' (Unfortunately C's promotion rules mean that in the expression "some_uint8_t_variable << 24" the LHS gets promoted to signed int before shifting.) Signed-off-by: Peter Maydell Reviewed-by: John Snow --- clang's undefined sanitizer produces a lot of copies of this warning during 'make check'... hw/ide/ahci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 796be15..21f76ed 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -548,7 +548,7 @@ static void ahci_init_d2h(AHCIDevice *ad) ad->init_d2h_sent = true; /* We're emulating receiving the first Reg H2D Fis from the device; * Update the SIG register, but otherwise proceed as normal. */ - pr->sig = (ide_state->hcyl << 24) | + pr->sig = ((uint32_t)ide_state->hcyl << 24) | (ide_state->lcyl << 16) | (ide_state->sector << 8) | (ide_state->nsector & 0xFF);