Fixed bitmap bug

svn path=/trunk/; revision=1429
This commit is contained in:
Eric Kohl 2000-11-19 15:58:58 +00:00
parent bd08f2070e
commit 885e8a3344

View file

@ -1,4 +1,4 @@
/* $Id: bitmap.c,v 1.1 2000/03/09 00:14:10 ekohl Exp $ /* $Id: bitmap.c,v 1.2 2000/11/19 15:58:58 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -11,9 +11,14 @@
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#define NDEBUG
#include <ntdll/ntdll.h>
#define ALIGN(x,align) (((x)+(align)-1) / (align)) #define ALIGN(x,align) (((x)+(align)-1) / (align))
/* FUNCTIONS *****************************************************************/
VOID VOID
STDCALL STDCALL
RtlInitializeBitMap ( RtlInitializeBitMap (
@ -38,14 +43,14 @@ RtlAreBitsClear (
ULONG Size = BitMapHeader->SizeOfBitMap; ULONG Size = BitMapHeader->SizeOfBitMap;
ULONG Shift; ULONG Shift;
ULONG Count; ULONG Count;
PCHAR Ptr; PUCHAR Ptr;
if (StartingIndex >= Size || if (StartingIndex >= Size ||
!Length || !Length ||
(StartingIndex + Length > Size)) (StartingIndex + Length > Size))
return FALSE; return FALSE;
Ptr = (PCHAR)BitMapHeader->Buffer + (StartingIndex / 8); Ptr = (PUCHAR)BitMapHeader->Buffer + (StartingIndex / 8);
while (Length) while (Length)
{ {
/* get bit shift in current byte */ /* get bit shift in current byte */
@ -55,9 +60,10 @@ RtlAreBitsClear (
Count = (Length > 8 - Shift) ? 8 - Shift : Length; Count = (Length > 8 - Shift) ? 8 - Shift : Length;
/* check byte */ /* check byte */
if (*Ptr++ & (~(0xFF << Count) << Shift)) if (*Ptr & (~(0xFF << Count) << Shift))
return FALSE; return FALSE;
Ptr++;
Length -= Count; Length -= Count;
StartingIndex += Count; StartingIndex += Count;
} }
@ -77,14 +83,15 @@ RtlAreBitsSet (
ULONG Size = BitMapHeader->SizeOfBitMap; ULONG Size = BitMapHeader->SizeOfBitMap;
ULONG Shift; ULONG Shift;
ULONG Count; ULONG Count;
PCHAR Ptr; PUCHAR Ptr;
UCHAR Check;
if (StartingIndex >= Size || if (StartingIndex >= Size ||
!Length || !Length ||
(StartingIndex + Length > Size)) (StartingIndex + Length > Size))
return FALSE; return FALSE;
Ptr = (PCHAR)BitMapHeader->Buffer + (StartingIndex / 8); Ptr = (PUCHAR)BitMapHeader->Buffer + (StartingIndex / 8);
while (Length) while (Length)
{ {
/* get bit shift in current byte */ /* get bit shift in current byte */
@ -93,10 +100,14 @@ RtlAreBitsSet (
/* get number of bits to check in current byte */ /* get number of bits to check in current byte */
Count = (Length > 8 - Shift) ? 8 - Shift : Length; Count = (Length > 8 - Shift) ? 8 - Shift : Length;
/* bulid check byte */
Check = ~(0xFF << Count) << Shift;
/* check byte */ /* check byte */
if (~*Ptr++ & (~(0xFF << Count) << Shift)) if ((*Ptr & Check) != Check)
return FALSE; return FALSE;
Ptr++;
Length -= Count; Length -= Count;
StartingIndex += Count; StartingIndex += Count;
} }
@ -146,7 +157,9 @@ RtlClearBits (
Count = (NumberToClear > 8 - Shift ) ? 8 - Shift : NumberToClear; Count = (NumberToClear > 8 - Shift ) ? 8 - Shift : NumberToClear;
/* adjust byte */ /* adjust byte */
*Ptr++ &= ~(~(0xFF << Count) << Shift); *Ptr &= ~(~(0xFF << Count) << Shift);
Ptr++;
NumberToClear -= Count; NumberToClear -= Count;
StartingIndex += Count; StartingIndex += Count;
} }
@ -640,7 +653,9 @@ RtlSetBits (
Count = (NumberToSet > 8 - Shift) ? 8 - Shift : NumberToSet; Count = (NumberToSet > 8 - Shift) ? 8 - Shift : NumberToSet;
/* adjust byte */ /* adjust byte */
*Ptr++ |= ~(0xFF << Count) << Shift; *Ptr |= ~(0xFF << Count) << Shift;
Ptr++;
NumberToSet -= Count; NumberToSet -= Count;
StartingIndex += Count; StartingIndex += Count;
} }