fix undefined shift in countLeadingZeros (#1157)

This commit is contained in:
Catena cyber 2018-06-03 16:26:12 +02:00 committed by Nguyen Anh Quynh
parent 3f1141452e
commit 14cdd65dd2
1 changed files with 7 additions and 4 deletions

View File

@ -425,14 +425,17 @@ static inline int64_t SignExtend64(uint64_t X, unsigned B) {
/// valid arguments.
static inline unsigned int countLeadingZeros(int x)
{
unsigned count = 0;
int i;
const unsigned bits = sizeof(x) * 8;
unsigned count = bits;
if (x < 0) {
return 0;
}
for (i = bits; --i; ) {
if (x < 0) break;
count++;
x <<= 1;
if (x == 0) break;
count--;
x >>= 1;
}
return count;