From: Avery Pennarun Date: Fri, 12 Feb 2010 19:53:19 +0000 (-0500) Subject: _hashsplit.c: right shifting 32 bits doesn't work. X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=666c08a8d1e99cd319b559e0c0f8c9804c01ced0;p=packages%2Fb%2Fbup.git _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. --- diff --git a/_hashsplit.c b/_hashsplit.c index a731454..e78f597 100644 --- a/_hashsplit.c +++ b/_hashsplit.c @@ -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;