lkml.org 
[lkml]   [2006]   [Jan]   [6]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
DateFri, 06 Jan 2006 16:13:47 +1100
FromPeter Williams <>
Subject[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>

-- 
Peter Williams                                   pwil3058@bigpond.net.au

"Learning, n. The kind of ignorance distinguishing the studious."
  -- Ambrose Bierce
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;
 
\
 
 \ /
  Last update: 2006-01-06 05:16    [from the cache]
©2003-2008