Fix regressions.

svn path=/trunk/; revision=44466
This commit is contained in:
Timo Kreuzer 2009-12-08 03:06:40 +00:00
parent 4e6d2d7136
commit 8d819f40bb

View file

@ -417,7 +417,7 @@ RtlFindClearBits(
IN ULONG NumberToFind, IN ULONG NumberToFind,
IN ULONG HintIndex) IN ULONG HintIndex)
{ {
ULONG CurrentBit, CurrentLength; ULONG CurrentBit, Margin, CurrentLength;
/* Check for valid parameters */ /* Check for valid parameters */
if (!BitMapHeader || NumberToFind > BitMapHeader->SizeOfBitMap) if (!BitMapHeader || NumberToFind > BitMapHeader->SizeOfBitMap)
@ -431,12 +431,15 @@ RtlFindClearBits(
return HintIndex; return HintIndex;
} }
/* First margin is end of bitmap */
Margin = BitMapHeader->SizeOfBitMap;
retry:
/* Start with hint index, length is 0 */ /* Start with hint index, length is 0 */
CurrentBit = HintIndex; CurrentBit = HintIndex;
CurrentLength = 0;
/* Loop until something is found or the end is reached */ /* Loop until something is found or the end is reached */
while (CurrentBit + NumberToFind < BitMapHeader->SizeOfBitMap) while (CurrentBit + NumberToFind < Margin)
{ {
/* Search for the next clear run, by skipping a set run */ /* Search for the next clear run, by skipping a set run */
CurrentBit += RtlpGetLengthOfRunSet(BitMapHeader, CurrentBit += RtlpGetLengthOfRunSet(BitMapHeader,
@ -458,6 +461,15 @@ RtlFindClearBits(
CurrentBit += CurrentLength; CurrentBit += CurrentLength;
} }
/* Did we start at a hint? */
if (HintIndex)
{
/* Retry at the start */
Margin = min(HintIndex + NumberToFind, BitMapHeader->SizeOfBitMap);
HintIndex = 0;
goto retry;
}
/* Nothing found */ /* Nothing found */
return MAXULONG; return MAXULONG;
} }
@ -571,10 +583,10 @@ RtlFindNextForwardRunClear(
/* Assume a set run first, count it's length */ /* Assume a set run first, count it's length */
Length = RtlpGetLengthOfRunSet(BitMapHeader, FromIndex, MAXULONG); Length = RtlpGetLengthOfRunSet(BitMapHeader, FromIndex, MAXULONG);
*StartingRunIndex = FromIndex; *StartingRunIndex = FromIndex + Length;
/* Now return the length of the run */ /* Now return the length of the run */
return RtlpGetLengthOfRunClear(BitMapHeader, FromIndex, MAXULONG); return RtlpGetLengthOfRunClear(BitMapHeader, FromIndex + Length, MAXULONG);
} }
ULONG ULONG
@ -647,7 +659,7 @@ RtlFindClearRuns(
} }
/* Advance bits */ /* Advance bits */
FromIndex += NumberOfBits; FromIndex = StartingIndex + NumberOfBits;
} }
/* Check if we are finished */ /* Check if we are finished */