]> arthur.barton.de Git - bup.git/commitdiff
_hashsplit.c: right shifting 32 bits doesn't work. bup-0.10
authorAvery Pennarun <apenwarr@gmail.com>
Fri, 12 Feb 2010 19:53:19 +0000 (14:53 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Fri, 12 Feb 2010 19:53:19 +0000 (14:53 -0500)
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.

_hashsplit.c

index a731454d9665eb7f3d30c1fa25dbd6244e6213a8..e78f5972eb82704139af4eb8a60bdbc2ca4d0350 100644 (file)
@@ -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;