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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 958C6C001B0 for ; Sun, 9 Jul 2023 11:41:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233037AbjGILli (ORCPT ); Sun, 9 Jul 2023 07:41:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229791AbjGILlg (ORCPT ); Sun, 9 Jul 2023 07:41:36 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EF6DBA; Sun, 9 Jul 2023 04:41:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=fIXPzfpDnl12CuFsfRY5j0Rj2DrqlsOG4+dLIdpRFxg=; b=OzogSOZmCXUCp5ZR5+BkWIiuEP 3fX9JvHGZFWBonRWhfURn/l5iVc+fu65rMnzGKZLfKXxhzyrDOK4UNs8J3IBdFiJTk93XNtWZIOa2 1j+Yil5vsY33aAAeQkyxTaQNpHjffygqcQU9MkbRi10DjVvzSrvFDKyF1AMVDEn9Uj5Aa8IAs7oR/ OAAvAG8cFCx+2olFtU7YtchRDAKErstNtwNeYX9KZibU2ic0Wd0jsqHxFjijPuZGvPYeDsck2mjp2 Aanp37zSKKs7Ra3sgxYsz//cEL3/TNF2CXBk1P0SKPtMiLXTNRk0xH+RSMObabF1PfHqE/OR3jcr7 n9KmMirg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qISn7-00DhEf-Ue; Sun, 09 Jul 2023 11:41:25 +0000 Date: Sun, 9 Jul 2023 12:41:25 +0100 From: Matthew Wilcox To: Linke Li Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Linke Li Subject: Re: [PATCH] isofs: fix undefined behavior in iso_date() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jul 09, 2023 at 02:42:55PM +0800, Linke Li wrote: > From: Linke Li > > Fix undefined behavior in the code by properly handling the left shift operaion. > Instead of left-shifting a negative value, explicitly cast -1 to an unsigned int > before the shift. This ensures well defined behavior and resolves any potential > issues. This certainly fixes the problem, but wouldn't it be easier to get the compiler to do the work for us? #include int f(unsigned char *p) { return (signed char)p[0]; } int main(void) { unsigned char x = 0xa5; printf("%d\n", f(&x)); return 0; } prints -91.