Permalink
Browse files

_hashsplit.c: right shifting 32 bits doesn't work.

in C, if you do
	uint32_t i = 0xffffffff;
	i >>= 32;

then the answer is 0xffffffff, not 0 as you might expect.  Let's shift it by
less than 32 at a time, which will give the right results.  This fixes a
rare infinite loop when counting the bits in the hashsplit.
  • Loading branch information...
1 parent a3ab444 commit 666c08a8d1e99cd319b559e0c0f8c9804c01ced0 @apenwarr apenwarr committed Feb 12, 2010
Showing with 2 additions and 1 deletion.
  1. +2 −1 _hashsplit.c
View
@@ -33,7 +33,8 @@ static int find_ofs(const unsigned char *buf, int len, int *bits)
if (bits)
{
*bits = BLOBBITS;
- for (*bits = BLOBBITS; (sum >> *bits) & 1; (*bits)++)
+ sum >>= BLOBBITS;
+ for (*bits = BLOBBITS; (sum >>= 1) & 1; (*bits)++)
;
}
return count+1;

0 comments on commit 666c08a

Please sign in to comment.