linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: torvalds@linux-foundation.org
Cc: David.Laight@aculab.com, mingo@kernel.org, hpa@zytor.com,
	tglx@linutronix.de, tytso@mit.edu, linux-kernel@vger.kernel.org,
	x86@kernel.org, netdev@vger.kernel.org,
	linux-ext4@vger.kernel.org
Subject: Re: Unsigned widening casts of binary "not" operations..
Date: Tue, 23 Apr 2013 13:37:32 -0400 (EDT)	[thread overview]
Message-ID: <20130423.133732.2222922370397287096.davem@davemloft.net> (raw)
In-Reply-To: <CA+55aFxvpcF7+dyy5d3+JP4Wfv90zPsRVtEhNG9Pky5gWTm_Pg@mail.gmail.com>

From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Tue, 23 Apr 2013 08:42:49 -0700

> An explicit cast fixes it, and shows that you were aware of the issue:
> 
>    foo &= ~(foo_t)bar;
> 
> and gcc will generate the right logic. Of course, casts then have
> their own problems, which your thing avoids (as would just having a
> "andn" operation in C)

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.

You all are very bright and probably know this already.

So,if it widens, which is the situation we're talking about, you're
good.  But until I saw the above u8 thing I never suspected that
narrowing in this kind of expression was dangerous.

  parent reply	other threads:[~2013-04-23 17:37 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CA+55aFwpLu0qNms=hkQr43yqD0K9DgESNm91OEWKT1ZuT8MU6Q@mail.gmail.com>
2013-04-23  0:23 ` Unsigned widening casts of binary "not" operations Linus Torvalds
2013-04-23  8:59   ` David Laight
2013-04-23 14:29     ` Linus Torvalds
2013-04-23 15:24       ` David Laight
2013-04-23 15:42         ` Linus Torvalds
2013-04-23 15:52           ` Theodore Ts'o
2013-04-23 16:05             ` Linus Torvalds
2013-04-23 17:37           ` David Miller [this message]
2013-04-23 17:52             ` Linus Torvalds
2013-04-23 17:56               ` David Miller
2013-04-23 18:21                 ` Linus Torvalds
2013-04-24 12:36             ` Geert Uytterhoeven
2013-04-23  0:32 ` H. Peter Anvin
2013-04-23 13:00 ` Theodore Ts'o
2013-04-24  7:26 ` Ingo Molnar
2013-04-24  7:47   ` Cyrill Gorcunov
2013-04-25  1:13     ` Lin Ming
2013-04-24 17:07   ` [PATCH] x86: make DR*_RESERVED unsigned long Oleg Nesterov
2013-04-24 18:45     ` H. Peter Anvin
2013-04-25 14:48       ` Oleg Nesterov
2013-04-26 16:38         ` [PATCH v2] " Oleg Nesterov
2013-04-26 16:44           ` H. Peter Anvin
2013-04-26 17:15             ` Oleg Nesterov
2013-04-27 14:45               ` Oleg Nesterov
2013-04-27 16:20                 ` H. Peter Anvin
2013-04-28  0:58                 ` Frederic Weisbecker
2013-04-28 17:27                   ` Oleg Nesterov
2013-04-28 17:32                     ` H. Peter Anvin
2013-04-28 17:39                       ` Oleg Nesterov
2013-04-28 17:43                         ` H. Peter Anvin
2013-04-24 22:48     ` [PATCH] " Frederic Weisbecker
2013-04-24 23:06       ` H. Peter Anvin
2013-04-24 23:31         ` Frederic Weisbecker
2013-04-25  1:20           ` H. Peter Anvin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130423.133732.2222922370397287096.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=David.Laight@aculab.com \
    --cc=hpa@zytor.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=tytso@mit.edu \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).