瀏覽代碼

[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 <pwil3058@bigpond.com.au>
Cc: Dave Jones <davej@codemonkey.org.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Peter Williams 19 年之前
父節點
當前提交
f0c00257d6
共有 1 個文件被更改,包括 1 次插入1 次删除
  1. 1 1
      lib/int_sqrt.c

+ 1 - 1
lib/int_sqrt.c

@@ -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;