From nobody Mon Sep 16 19:18:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1721749385; cv=none; d=zohomail.com; s=zohoarc; b=QhXh7MwmuDuNhZ7Fq1Ti1cljtlmipA3ad4A2er75oAUs0Y7fXligfC4NTItiH1i2612jPAH0piwISXydROjsPWK61/mJPNfy7EdFvGFB4M3i/YiB4O+xrakQGrgy7ZBoNcVleNpAlH0V3sInCiS1yO1aNervlGiH12vmQKfKA08= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1721749385; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=z+QzS9QA9QvOiWnY8XIiTLDO7LUpB/9AuTBIybu/pEo=; b=aL6pRGlMkjxJsA1S+XX6cmpbDrgO8GZz5py+TTwpVbtc7M2P4OoCpgE0VMzYuaJSR0HDS0Y4Pe2LstiKkB85QOkv+oyuFMsqOPnVxaXbwiQitBbdMMquf45/0Z9DgnkHv6r6v/jI7OGb/KnQgBFgcKdudtz3CFUKSn4be1pQt/k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1721749385256597.8424500781991; Tue, 23 Jul 2024 08:43:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sWHeY-0004b3-LD; Tue, 23 Jul 2024 11:42:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sWHeW-0004aH-S6 for qemu-devel@nongnu.org; Tue, 23 Jul 2024 11:42:12 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sWHeV-0007qs-4V for qemu-devel@nongnu.org; Tue, 23 Jul 2024 11:42:12 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-368440b073bso2868261f8f.0 for ; Tue, 23 Jul 2024 08:42:10 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36878694833sm11858198f8f.55.2024.07.23.08.42.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jul 2024 08:42:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721749329; x=1722354129; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=z+QzS9QA9QvOiWnY8XIiTLDO7LUpB/9AuTBIybu/pEo=; b=KJckQogUKng5Dy38/H9ru4LZj9tdySsM/Wee3FcckjmqRpjOlE0xim4jKjkWujx0vC +fsPKksko/k7tz+pY912/l0905G+pwS2WA+Fp9DRP/EIufG2QJFmYKk/jKWeMwMafEkF 53U19xcu/YXLRn03yHVbHMNoaTIu/W6XKH0davUc0KcQC9Hsqp1sc6bd6ks8uAXGkTiY Irg8GehmUmO8s0yrBXNJm9yxphXJOw+sZe4hNdk8pq/Mb9W6IVPsSqvUnjohJlwOF1XL 8sp+6vkl9J7jgK7nrtwwpCFpr4SqEyKWZPl/3gFhmQJAplUdo6vfriEfvENfXpucfY7X eb/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721749329; x=1722354129; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=z+QzS9QA9QvOiWnY8XIiTLDO7LUpB/9AuTBIybu/pEo=; b=Yl+8KHJNFXJ/C19HdvtEScir2EFfkmsc4vKAOylNi3B/fnrbVYR2KtMpy/kUwSRvNY O1dAXG9RfqurRCwgBPi2DjELS9PTOvuWF7hM/ytE9ombLmA2ID9t2wZ9yDJDg3NIKktA nnvXKLcVq7zQj1X3CWz0Togzf4vZP4wdmQcvrLQIJHDqJ5wwoGpkn9ivlByGQNRr/6sW uZpgqdNNwuW4ABu62pXgBsgfi2rKgvoNrhkgYIp/tjhDmuDnNvTqF9IVbXoUWFEI4UX+ GgCdEhfoLUVvG8ULc/Lp9ntnAHQXSBhgAZds8J6AeybxTNIFrXq7U3MZZ9rGSlnHbBEV TK8Q== X-Gm-Message-State: AOJu0Yw5jBa899EJ9tcYurS4uVX7FD2Gm+lypEbLD5fW3hnbOKjXI/IY MzvsGCztC+OnEcKmjdouf3WQCxLl14jXdKPZEm8FtPOVcXg9qCkbIJe+oBCxDidX4r4eo1HTCv1 2 X-Google-Smtp-Source: AGHT+IFRlXsHz++WfB7YODqOIAi6LA4seUVxC0ISLmd3ZvoOX59FqKWcmPto1nmLFADTZymRJeLleA== X-Received: by 2002:a5d:64ac:0:b0:367:8e52:3bb9 with SMTP id ffacd0b85a97d-369e3f179b3mr2443752f8f.22.1721749328939; Tue, 23 Jul 2024 08:42:08 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Laurent Vivier Subject: [PATCH] target/m68k: avoid shift into sign bit in dump_address_map() Date: Tue, 23 Jul 2024 16:42:07 +0100 Message-Id: <20240723154207.1483665-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1721749386434116600 Content-Type: text/plain; charset="utf-8" Coverity complains (CID 1547592) that in dump_address_map() we take a value stored in a signed integer variable 'i' and shift it by enough to shift into the sign bit when we construct the value 'logical'. This isn't a bug for QEMU because we use -fwrapv semantics, but we can make Coverity happy by using an unsigned type for the loop variables i, j, k in this function. While we're changing the declaration of the variables, put them in the for() loops so their scope is the minimum required (a style now permitted by our coding style guide). Resolves: Coverity CID 1547592 Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- I could have just marked this as a false-positive, but it just about seemed worth making the change overall. --- target/m68k/helper.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/target/m68k/helper.c b/target/m68k/helper.c index 7967ad13cbf..4c85badd5d3 100644 --- a/target/m68k/helper.c +++ b/target/m68k/helper.c @@ -479,7 +479,6 @@ static void print_address_zone(uint32_t logical, uint32= _t physical, =20 static void dump_address_map(CPUM68KState *env, uint32_t root_pointer) { - int i, j, k; int tic_size, tic_shift; uint32_t tib_mask; uint32_t tia, tib, tic; @@ -502,19 +501,19 @@ static void dump_address_map(CPUM68KState *env, uint3= 2_t root_pointer) tic_shift =3D 12; tib_mask =3D M68K_4K_PAGE_MASK; } - for (i =3D 0; i < M68K_ROOT_POINTER_ENTRIES; i++) { + for (unsigned i =3D 0; i < M68K_ROOT_POINTER_ENTRIES; i++) { tia =3D address_space_ldl(cs->as, M68K_POINTER_BASE(root_pointer) = + i * 4, MEMTXATTRS_UNSPECIFIED, &txres); if (txres !=3D MEMTX_OK || !M68K_UDT_VALID(tia)) { continue; } - for (j =3D 0; j < M68K_ROOT_POINTER_ENTRIES; j++) { + for (unsigned j =3D 0; j < M68K_ROOT_POINTER_ENTRIES; j++) { tib =3D address_space_ldl(cs->as, M68K_POINTER_BASE(tia) + j *= 4, MEMTXATTRS_UNSPECIFIED, &txres); if (txres !=3D MEMTX_OK || !M68K_UDT_VALID(tib)) { continue; } - for (k =3D 0; k < tic_size; k++) { + for (unsigned k =3D 0; k < tic_size; k++) { tic =3D address_space_ldl(cs->as, (tib & tib_mask) + k * 4, MEMTXATTRS_UNSPECIFIED, &txres); if (txres !=3D MEMTX_OK || !M68K_PDT_VALID(tic)) { --=20 2.34.1