Skip to content

Commit

Permalink
[PATCH] lib: Fix bug in int_sqrt() for 64 bit longs
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
pwil3058 authored and Linus Torvalds committed Feb 3, 2006
1 parent 6bf8d88 commit f0c0025
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/int_sqrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit f0c0025

Please sign in to comment.