From nobody Mon Feb 9 11:32:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488556290640366.88104244140436; Fri, 3 Mar 2017 07:51:30 -0800 (PST) Received: from localhost ([::1]:58732 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjpUP-0005cS-Hc for importer@patchew.org; Fri, 03 Mar 2017 10:51:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46636) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjpTh-0005b6-Fi for qemu-devel@nongnu.org; Fri, 03 Mar 2017 10:50:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cjpTb-0002uF-W3 for qemu-devel@nongnu.org; Fri, 03 Mar 2017 10:50:45 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:48731) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cjpTb-0002rd-PT for qemu-devel@nongnu.org; Fri, 03 Mar 2017 10:50:39 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1cjpTa-0006ER-68; Fri, 03 Mar 2017 15:50:38 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 3 Mar 2017 15:50:33 +0000 Message-Id: <1488556233-31246-7-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488556233-31246-1-git-send-email-peter.maydell@linaro.org> References: <1488556233-31246-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH for-2.9 6/6] disas/arm: Avoid unintended sign extension X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , patches@linaro.org, Laurent Vivier , Paolo Bonzini , "Edgar E. Iglesias" , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When assembling 'given' from the instruction bytes, C's integer promotion rules mean we may promote an unsigned char to a signed integer before shifting it, and then sign extend to a 64-bit long, which can set the high bits of the long. The code doesn't in fact care about the high bits if the long is 64 bits, but this is surprising, so don't do it. (Spotted by Coverity, CID 1005404.) Signed-off-by: Peter Maydell --- Arguably 'given' should be uint32_t here rather than 'long', but a small change to placate Coverity seemed wiser than a wholesale change of the type of the 'given' variables/arguments through the whole file, since this is 3rd-party code that's known to work. --- disas/arm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/disas/arm.c b/disas/arm.c index 93c6503..27396dd 100644 --- a/disas/arm.c +++ b/disas/arm.c @@ -3901,9 +3901,9 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *= info) =20 status =3D info->read_memory_func (pc, (bfd_byte *)b, 4, info); if (little) - given =3D (b[0]) | (b[1] << 8) | (b[2] << 16) | (b[3] << 24); + given =3D (b[0]) | (b[1] << 8) | (b[2] << 16) | ((unsigned)b[3] << 24); else - given =3D (b[3]) | (b[2] << 8) | (b[1] << 16) | (b[0] << 24); + given =3D (b[3]) | (b[2] << 8) | (b[1] << 16) | ((unsigned)b[0] << 24); } else { --=20 2.7.4