]> Git Repo - linux.git/commitdiff
[PATCH] lib: Fix bug in int_sqrt() for 64 bit longs
authorPeter Williams <[email protected]>
Fri, 3 Feb 2006 11:04:33 +0000 (03:04 -0800)
committerLinus Torvalds <[email protected]>
Fri, 3 Feb 2006 16:32:08 +0000 (08:32 -0800)
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 <[email protected]>
Cc: Dave Jones <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
lib/int_sqrt.c

index a5d2cdc5684cfdf0d2834692c3abc6024da515de..fd355a99327cdeab8333781991ea3ecd59997ca4 100644 (file)
@@ -15,7 +15,7 @@ unsigned long int_sqrt(unsigned long x)
        op = x;
        res = 0;
 
-       one = 1 << 30;
+       one = 1UL << (BITS_PER_LONG - 2);
        while (one > op)
                one >>= 2;
 
This page took 0.05623 seconds and 4 git commands to generate.