Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp34128322rwd; Sun, 9 Jul 2023 05:49:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlFIa6Dfvvzo9W6yHR2V9lPnZNXH6v/pNGfVbWLcN1NCGAqwvdGszUfYVpZJIb2snMUuUU4F X-Received: by 2002:a05:6a20:8e25:b0:10f:52e2:49ec with SMTP id y37-20020a056a208e2500b0010f52e249ecmr10197789pzj.53.1688906996423; Sun, 09 Jul 2023 05:49:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688906996; cv=none; d=google.com; s=arc-20160816; b=NwCjc2tALCtPXfE5MIKu4m6mU0J5sBQPyOH7qkpE5BRWjd5FCyqcuajDuOkPiPvpXp HISbvaoRB+R37GhwwUr5ophHxosEPeNoX+eHaNLQ1s+wRFtvOxc1iGIo3FW4jvxM75DN ncOwrbwfxrqKZtrKhft1QVp3Y/V7sw1xvkHWsmy5TBkoHLSERvflN9H1f5t9ARuVwrjH 1A13hEQbLPK9EyJldF1iPIXjIgOd8D773j/Ckax4HD2UR/4+xEHQ7ua0U2C+watTgjyQ jLP99I3hynYUKe1C11xt33VXGxT3T9tGPbSVtFUuKbMlFE6BHOt558B6FOGFtrVoVp9Z DBdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=fIXPzfpDnl12CuFsfRY5j0Rj2DrqlsOG4+dLIdpRFxg=; fh=ApCmPSGE9NyzAEwDM8J/wMzuAHIJShz728eGck45vu0=; b=TAF5BCVHk38Cz8zCrKoyWmbqGlCMqcPm9gQhkfqBojqVxxGF3isxH0Xj/MOBEUDhyC 38Nuj9kH5GG2+aQo4hfXaqz63yJdhgK9lvdlBW2YXG0FzO6MLRWDw5sMAAP3/wJb9KJ/ RMCDk0tm6cUCCPNiKd5q6MeSRCTMqXngF8n5a5ew3y4qiXd2yE7ef8TG5EtoYy6cB99k DLMDMoRCfoQ59uHJJlr3rhCipbFmjS/1Pdq3JqFaYLE4tKx3264BpG2DDd3vO17iBSof 6g1mDN5NdcFWjUVBR/9rBFj2q8tSp3DCip6fbNmhVlbmykzz3WW9rmNZR+UgSbptaug7 BfiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=OzogSOZm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv127-20020a632e85000000b0054fd6863325si7060090pgb.726.2023.07.09.05.49.44; Sun, 09 Jul 2023 05:49:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=OzogSOZm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233026AbjGILlh (ORCPT + 99 others); Sun, 9 Jul 2023 07:41:37 -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: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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.