From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 48AA4C3DA63 for ; Wed, 24 Jul 2024 03:00:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sWSF2-0000NQ-Ny; Tue, 23 Jul 2024 23:00:36 -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 1sWSEn-0007zo-TO for qemu-devel@nongnu.org; Tue, 23 Jul 2024 23:00:25 -0400 Received: from ik1-413-38519.vs.sakura.ne.jp ([153.127.30.23] helo=sakura.ysato.name) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sWSEg-0002k5-9S for qemu-devel@nongnu.org; Tue, 23 Jul 2024 23:00:16 -0400 Received: from SIOS1075.ysato.ml (al128006.dynamic.ppp.asahi-net.or.jp [111.234.128.6]) by sakura.ysato.name (Postfix) with ESMTPSA id 952C81C00D1; Wed, 24 Jul 2024 12:00:04 +0900 (JST) Date: Wed, 24 Jul 2024 12:00:04 +0900 Message-ID: <871q3jebpn.wl-ysato@users.sourceforge.jp> From: Yoshinori Sato To: Peter Maydell Cc: qemu-devel@nongnu.org Subject: Re: [PATCH] target/sh4: Avoid shift into sign bit in update_itlb_use() In-Reply-To: <20240723172431.1757296-1-peter.maydell@linaro.org> References: <20240723172431.1757296-1-peter.maydell@linaro.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.3 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Received-SPF: softfail client-ip=153.127.30.23; envelope-from=ysato@users.sourceforge.jp; helo=sakura.ysato.name X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 5.0 requ) BAYES_00=-1.9, KHOP_HELO_FCRDNS=0.26, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On Wed, 24 Jul 2024 02:24:31 +0900, Peter Maydell wrote: > > 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 > --- > 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: > -- > 2.34.1 > Reviewed-by: Yoshinori Sato -- Yosinori Sato