All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <dada1@cosmosbay.com>
To: Peter Williams <pwil3058@bigpond.net.au>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] lib: Fix bug in int_sqrt() for 64 bit longs
Date: Fri, 06 Jan 2006 07:42:48 +0100	[thread overview]
Message-ID: <43BE1168.1090706@cosmosbay.com> (raw)
In-Reply-To: <43BDFC8B.9020805@bigpond.net.au>

Peter Williams a écrit :
> The implementation of int_sqrt() assumes that longs have 32 bits.  On 
> systems that have 64 bit longs this will result in gross errors when the 
> argument to the function is greater than 2^32 - 1 on such systems. I 
> doubt whether any such use is currently made of int_sqrt() but the 
> attached patch fixes the problem anyway.
> 
> Signed-off-by: Peter Williams <pwil3058@bigpond.com.au>
> 
> 
> ------------------------------------------------------------------------
> 
> Index: GIT-warnings/lib/int_sqrt.c
> ===================================================================
> --- GIT-warnings.orig/lib/int_sqrt.c	2005-10-25 13:55:22.000000000 +1000
> +++ GIT-warnings/lib/int_sqrt.c	2006-01-06 14:29:19.000000000 +1100
> @@ -15,7 +15,7 @@ unsigned long int_sqrt(unsigned long x)
>  	op = x;
>  	res = 0;
>  
> -	one = 1 << 30;
> +	one = 1 << (BITS_PER_LONG - 2);
>  	while (one > op)
>  		one >>= 2;
>  

Are you sure it works ?

I would have writen :

one = 1L << (BITS_PER_LONG - 2);

Eric

  reply	other threads:[~2006-01-06  6:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-06  5:13 [PATCH] lib: Fix bug in int_sqrt() for 64 bit longs Peter Williams
2006-01-06  6:42 ` Eric Dumazet [this message]
2006-01-06 23:21   ` Peter Williams

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=43BE1168.1090706@cosmosbay.com \
    --to=dada1@cosmosbay.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pwil3058@bigpond.net.au \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.