Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756914Ab3DWRwg (ORCPT ); Tue, 23 Apr 2013 13:52:36 -0400 Received: from mail-vb0-f42.google.com ([209.85.212.42]:61122 "EHLO mail-vb0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756667Ab3DWRwe (ORCPT ); Tue, 23 Apr 2013 13:52:34 -0400 MIME-Version: 1.0 In-Reply-To: <20130423.133732.2222922370397287096.davem@davemloft.net> References: <20130423.133732.2222922370397287096.davem@davemloft.net> Date: Tue, 23 Apr 2013 10:52:33 -0700 X-Google-Sender-Auth: pORGlCX3FGa5TQMHHga7QTYeoyE Message-ID: Subject: Re: Unsigned widening casts of binary "not" operations.. From: Linus Torvalds To: David Miller Cc: David Laight , Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , "Theodore Ts'o" , Linux Kernel Mailing List , "the arch/x86 maintainers" , Network Development , "linux-ext4@vger.kernel.org" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 950 Lines: 22 On Tue, Apr 23, 2013 at 10:37 AM, David Miller wrote: > > I just want to mention that this is dangerous in different ways, we > just recently got a patch in the networking that removed such a cast. > The problem is when the cast narrows, f.e.: > > ~(u8)0 > > doesn't do what you think it does. That doesn't evaluate to 0xff. Yeah, sparse will get that right, but won't warn about it even with my patch. The normal "all arithmetic is done in *at*least* 'int'" will always kick any C expression like that up to 'int' before the binary not op is done. So in your example, the implicit cast is widening the value *before* the binary not, not after. Linus -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/