Author: tkreuzer
Date: Mon Jul 4 16:30:45 2011
New Revision: 52536
URL:
http://svn.reactos.org/svn/reactos?rev=52536&view=rev
Log:
[RTL]
- Fix RtlFindSetBits to search for bits before the HintIndex as well
- Remove a wrong (and commented out) ASSERT
- Fix MSVC warnings
Modified:
trunk/reactos/lib/rtl/bitmap.c
Modified: trunk/reactos/lib/rtl/bitmap.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/bitmap.c?rev=52536…
==============================================================================
--- trunk/reactos/lib/rtl/bitmap.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/bitmap.c [iso-8859-1] Mon Jul 4 16:30:45 2011
@@ -152,11 +152,11 @@
if (BitScanReverse(&Position, Value >> 32))
{
- return Position + 32;
+ return (CCHAR)(Position + 32);
}
else if (BitScanReverse(&Position, (ULONG)Value))
{
- return Position;
+ return (CCHAR)Position;
}
return -1;
@@ -170,11 +170,11 @@
if (BitScanForward(&Position, (ULONG)Value))
{
- return Position;
+ return (CCHAR)Position;
}
else if (BitScanForward(&Position, Value >> 32))
{
- return Position + 32;
+ return (CCHAR)(Position + 32);
}
return -1;
@@ -187,9 +187,6 @@
IN PULONG BitMapBuffer,
IN ULONG SizeOfBitMap)
{
- // FIXME: some bugger here!
- //ASSERT(SizeOfBitMap > 0);
-
/* Setup the bitmap header */
BitMapHeader->SizeOfBitMap = SizeOfBitMap;
BitMapHeader->Buffer = BitMapBuffer;
@@ -212,7 +209,7 @@
IN OUT PRTL_BITMAP BitMapHeader)
{
ULONG LengthInUlongs;
-
+
LengthInUlongs = (BitMapHeader->SizeOfBitMap + 31) >> 5;
RtlFillMemoryUlong(BitMapHeader->Buffer, LengthInUlongs << 2, ~0);
}
@@ -481,7 +478,7 @@
IN ULONG NumberToFind,
IN ULONG HintIndex)
{
- ULONG CurrentBit, CurrentLength;
+ ULONG CurrentBit, Margin, CurrentLength;
/* Check for valid parameters */
if (!BitMapHeader || NumberToFind > BitMapHeader->SizeOfBitMap)
@@ -495,12 +492,15 @@
return HintIndex;
}
+ /* First margin is end of bitmap */
+ Margin = BitMapHeader->SizeOfBitMap;
+
+retry:
/* Start with hint index, length is 0 */
CurrentBit = HintIndex;
- CurrentLength = 0;
/* Loop until something is found or the end is reached */
- while (CurrentBit + NumberToFind <= BitMapHeader->SizeOfBitMap)
+ while (CurrentBit + NumberToFind <= Margin)
{
/* Search for the next set run, by skipping a clear run */
CurrentBit += RtlpGetLengthOfRunClear(BitMapHeader,
@@ -522,6 +522,15 @@
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 */
return MAXULONG;
}
@@ -641,7 +650,7 @@
for (Run = 0; Run < SizeOfRunArray; Run++)
{
/* Look for a run */
- NumberOfBits = RtlFindNextForwardRunClear(BitMapHeader,
+ NumberOfBits = RtlFindNextForwardRunClear(BitMapHeader,
FromIndex,
&StartingIndex);
@@ -672,7 +681,7 @@
while (1)
{
/* Look for a run */
- NumberOfBits = RtlFindNextForwardRunClear(BitMapHeader,
+ NumberOfBits = RtlFindNextForwardRunClear(BitMapHeader,
FromIndex,
&StartingIndex);
@@ -716,7 +725,7 @@
while (1)
{
/* Look for a run */
- NumberOfBits = RtlFindNextForwardRunClear(BitMapHeader,
+ NumberOfBits = RtlFindNextForwardRunClear(BitMapHeader,
FromIndex,
&Index);
@@ -749,7 +758,7 @@
while (1)
{
/* Look for a run */
- NumberOfBits = RtlFindNextForwardRunSet(BitMapHeader,
+ NumberOfBits = RtlFindNextForwardRunSet(BitMapHeader,
FromIndex,
&Index);