Skip to content

Commit f0c0025

Browse files
pwil3058Linus Torvalds
authored and
Linus Torvalds
committed
[PATCH] lib: Fix bug in int_sqrt() for 64 bit longs
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]>
1 parent 6bf8d88 commit f0c0025

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/int_sqrt.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ unsigned long int_sqrt(unsigned long x)
1515
op = x;
1616
res = 0;
1717

18-
one = 1 << 30;
18+
one = 1UL << (BITS_PER_LONG - 2);
1919
while (one > op)
2020
one >>= 2;
2121

0 commit comments

Comments
 (0)