- Fix small bug in RtlFindMostSignificantBit. It returned sometimes

wrong results if more then one bit was set.
- Update the test cases as well.
This commit is contained in:
Thomas Mertes 2003-02-18 23:22:49 +00:00 committed by Alexandre Julliard
parent d0e4a76544
commit 38012942f8
2 changed files with 17 additions and 5 deletions

View File

@ -592,9 +592,9 @@ CCHAR WINAPI RtlFindMostSignificantBit(ULONGLONG ulLong)
{
if (*lpOut)
{
if (*lpOut & 0x0f)
return lCount - 8 + NTDLL_mostSignificant[*lpOut & 0x0f];
return lCount - 4 + NTDLL_mostSignificant[*lpOut >> 4];
if (*lpOut & 0xf0)
return lCount - 4 + NTDLL_mostSignificant[*lpOut >> 4];
return lCount - 8 + NTDLL_mostSignificant[*lpOut & 0x0f];
}
lpOut--;
}

View File

@ -444,7 +444,13 @@ static void test_RtlFindMostSignificantBit()
ulLong <<= i;
cPos = pRtlFindMostSignificantBit(ulLong);
ok (cPos == i, "didnt find MSB %lld %d %d", ulLong, i, cPos);
ok (cPos == i, "didnt find MSB %llx %d %d", ulLong, i, cPos);
/* Set all bits lower than bit i */
ulLong = ((ulLong - 1) << 1) | 1;
cPos = pRtlFindMostSignificantBit(ulLong);
ok (cPos == i, "didnt find MSB %llx %d %d", ulLong, i, cPos);
}
cPos = pRtlFindMostSignificantBit(0);
ok (cPos == -1, "found bit when not set");
@ -465,7 +471,13 @@ static void test_RtlFindLeastSignificantBit()
ulLong <<= i;
cPos = pRtlFindLeastSignificantBit(ulLong);
ok (cPos == i, "didnt find LSB at %d", cPos);
ok (cPos == i, "didnt find LSB %llx %d %d", ulLong, i, cPos);
ulLong = 0xfffffffffffffffful;
ulLong <<= i;
cPos = pRtlFindLeastSignificantBit(ulLong);
ok (cPos == i, "didnt find LSB %llx %d %d", ulLong, i, cPos);
}
cPos = pRtlFindLeastSignificantBit(0);
ok (cPos == -1, "found bit when not set");