From patchwork Tue Jul 23 17:24:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 813960 Delivered-To: patch@linaro.org Received: by 2002:adf:f288:0:b0:367:895a:4699 with SMTP id k8csp2424179wro; Tue, 23 Jul 2024 10:25:41 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXwbDKb3MRf0sJ9b/bEjqArFhjzV9jjppGXTcxo+GirCAmFDqSzwX+dDLXTk5EcKmHtxKCzArFysjt1RkHhoxa/ X-Google-Smtp-Source: AGHT+IEdrfJJyjJbmi/DQOmydwYr1kHo9Wx3ajPfEnfXSf258Q6OlcgBVC4nMmxNcPYCXc6PodcQ X-Received: by 2002:a05:6214:76e:b0:6b7:97d1:9a94 with SMTP id 6a1803df08f44-6b98edd1aeamr3485346d6.36.1721755541259; Tue, 23 Jul 2024 10:25:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721755541; cv=none; d=google.com; s=arc-20160816; b=jq+W+bM7j5JBUvy91ZmALw+qJZApQboEARTLUDdPfPGINdLmBcFZNZguK7m6gLELke 3Y6bkLOT+PvV8xpRSJS1x86jiMcJzuB3Qr05M7l63NEbsl37UQhSMSJzhCvCcdLIq3Jg YGsZl1IxAhOuCEiOQRxERcBpr0QYblECB4I1P52t/OmL1464FKavlv18aKZ9Xg1DUjn9 v7AhlDrR5rbrAsg8T9XXAWZTchju6nqEGqdUmoROaeI+q0IHFbQTuv1JF5q6U5+GieNA 12dZ3rWYO72ll7EEiInevSQmyMD54+nK80y3n6jI+7ce+EtWR5F83IgPr9vKIlOaWgjb ZVOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=k2czhJvtkMfqRXVZ9gzbq0AkCoGEcqVzVE/Mgbbqq84=; fh=pKcF2rWkV2U4m2Lap+jKYjpOmXas0tDx61/9YVDomkY=; b=TcY3PKphNZ8umDFaAERO9EigdIsEgKXmSuI8WYDvays3QQyjZPWoNz0fkjxkjh7YLo aPjBnVVFOFECT/xEGUeKZHTwKtos+QtkWr3EIOPB9GhbhHddxfKPaH6nXdoh+fZHpQMk yL7Tiv0gSqoVMf3UCwUtgYfIXcWjl5EVS+7wfAomLSuLUBRwG8TDzHPLm0MHwrILDCmR Del5H1tWONoSpaxbF7XeZfBd9ulT2NvHKTJHO3OOkaREXrDNn3cyok8UD/fWbF3KRrly g8aT1c+HIeVCpLGz+lKEQw/lbIK5DaYASXXhX6+nBNmAyKQbacaql8xEfV1UPHhsJoGz y7AA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QUZfItPS; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6b7ac999eb1si109717746d6.228.2024.07.23.10.25.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2024 10:25:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QUZfItPS; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sWJFi-0000MW-8U; Tue, 23 Jul 2024 13:24:42 -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 1sWJFf-0000L6-M8 for qemu-devel@nongnu.org; Tue, 23 Jul 2024 13:24:39 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sWJFb-0001xT-UC for qemu-devel@nongnu.org; Tue, 23 Jul 2024 13:24:38 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3685afd0c56so1463658f8f.1 for ; Tue, 23 Jul 2024 10:24:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721755473; x=1722360273; 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=k2czhJvtkMfqRXVZ9gzbq0AkCoGEcqVzVE/Mgbbqq84=; b=QUZfItPS4+rS5luaOCfXMOhAAS0hCuJ6Q60w+NLz2+nU7iMH5l9Yf/eEnD1LgjDzY9 FqAJn8PHRyynxVBDVqw0mHyVPq5EOOMrv9cqtno848o5BB13nZfbSH2XG5QK8rV1w7dW W1/SkRx8yzbnQEdVPHoFoyTKfGwC/XNejPXTjSHpc7dbUhhm4xLGSrtL/e4jzcwK1r1J ANRgSNcWZDXOeUdNPqYw/ZEB9vrRm8KYfySvytv7HZcp/p2HTf9YE23EZBEzoYQgjGjY p6ew0V4HtEWPCN95HVeY39bWcAkIVrCqLgf+/i+DAoE2D1T473GApnEnB1EKvFnQpYJH +KbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721755473; x=1722360273; 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=k2czhJvtkMfqRXVZ9gzbq0AkCoGEcqVzVE/Mgbbqq84=; b=KRm9vPb9kvjgSm044G0/ONjn2IeKXm0nnP6hzlyKmC8gPYxI71JKs6W+nDUTLp2HOX kuj/vvk4sqPg5Lo06aEf8yMqvOJDycDYtJEV0fyCZk/F1/X5gof1c+2UosYJhGY88GuD mZB0mNZUlSb5s8mxcGlo36cS9VwQVNZenahr8TmkmO7Nbz4SforCosoSeoVc5OO6Ngr4 vEwBcmB6Gxmajk6kXIdxmD4FPWXBGvouBJPq86antPpTpP2XMrMulNvytnvVSYvttWh9 unJ701eeWh2EfjD0YNkErOFiAD1evHnfXSDLmpIt15zv5NK6PcPrUeYrlz6yF9xsRwzg eBxQ== X-Gm-Message-State: AOJu0YxtSXHs7kyTsl4K3GsKlJbqZox0wctyOj7qUqCEU9TYtNz/NC2w F5ZoWe8mJLiRxfwWkxaofSnujUIZ3fVrO2rLu8CtXtKWcnyzy3dIgrcDa/CAJayTc9JeDeuoMXn 5 X-Received: by 2002:adf:e70a:0:b0:367:980a:6aa with SMTP id ffacd0b85a97d-369bb2a19camr7174141f8f.54.1721755472948; Tue, 23 Jul 2024 10:24:32 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-368787ceda0sm12065827f8f.87.2024.07.23.10.24.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jul 2024 10:24:32 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Yoshinori Sato Subject: [PATCH] target/sh4: Avoid shift into sign bit in update_itlb_use() Date: Tue, 23 Jul 2024 18:24:31 +0100 Message-Id: <20240723172431.1757296-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42b.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org In update_itlb_use() the variables or_mask and and_mask are uint8_t, which means that in expressions like "and_mask << 24" the usual C arithmetic conversions will result in the shift being done as a signed int type, and so we will shift into the sign bit. For QEMU this isn't undefined behaviour because we use -fwrapv; but we can avoid it anyway by using uint32_t types for or_mask and and_mask. Resolves: Coverity CID 1547628 Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Reviewed-by: Yoshinori Sato --- target/sh4/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/sh4/helper.c b/target/sh4/helper.c index 67029106277..9659c695504 100644 --- a/target/sh4/helper.c +++ b/target/sh4/helper.c @@ -187,7 +187,7 @@ void superh_cpu_do_interrupt(CPUState *cs) static void update_itlb_use(CPUSH4State * env, int itlbnb) { - uint8_t or_mask = 0, and_mask = (uint8_t) - 1; + uint32_t or_mask = 0, and_mask = 0xff; switch (itlbnb) { case 0: