mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@suse.de>
To: Peter Lund <firefly@vax64.dk>
Cc: Christoph Lameter <clameter@sgi.com>,
	Christoph Hellwig <hch@infradead.org>,
	trivial@kernel.org, linux-kernel@vger.kernel.org,
	Momchil Velikov <velco@fadata.bg>,
	"Maciej W. Rozycki" <macro@linux-mips.org>
Subject: Re: [PATCH] avoid negative shifts in radix-tree.c, take 2
Date: Wed, 29 Aug 2007 14:47:17 +0200	[thread overview]
Message-ID: <jeodgq1p9m.fsf@sykes.suse.de> (raw)
In-Reply-To: <1188390865.7216.5.camel@localhost.localdomain> (Peter Lund's message of "Wed\, 29 Aug 2007 14\:34\:25 +0200")

Peter Lund <firefly@vax64.dk> writes:

> Shifting by more than the width of the value on the left is also not allowed.

Shifting by the width of the value is not allowed as well.

> --- linux-2.6.22/lib/radix-tree.c.orig	2007-08-27 15:42:37.000000000 +0200
> +++ linux-2.6.22/lib/radix-tree.c	2007-08-29 13:19:19.000000000 +0200
> @@ -980,12 +980,13 @@
>  
>  static __init unsigned long __maxindex(unsigned int height)
>  {
> -	unsigned int tmp = height * RADIX_TREE_MAP_SHIFT;
> -	unsigned long index = (~0UL >> (RADIX_TREE_INDEX_BITS - tmp - 1)) >> 1;
> +	unsigned int width = height * RADIX_TREE_MAP_SHIFT;
> +	int          shift = RADIX_TREE_INDEX_BITS - width;
>  
> -	if (tmp >= RADIX_TREE_INDEX_BITS)
> -		index = ~0UL;
> -	return index;
> +	if (shift < 0)
> +		return ~0UL;
> +	else
> +		return ~0UL >> shift;

Since height can be zero, you still have undefined behaviour.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

      reply	other threads:[~2007-08-29 12:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-29 12:34 Peter Lund
2007-08-29 12:47 ` Andreas Schwab [this message]

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=jeodgq1p9m.fsf@sykes.suse.de \
    --to=schwab@suse.de \
    --cc=clameter@sgi.com \
    --cc=firefly@vax64.dk \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=macro@linux-mips.org \
    --cc=trivial@kernel.org \
    --cc=velco@fadata.bg \
    /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

all inboxes | Powered by JetHome®