Fixed buggy RtlCompareString() and RtlCompareUnicodeString()

svn path=/trunk/; revision=991
This commit is contained in:
Eric Kohl 2000-02-19 19:31:41 +00:00
parent f28a023c99
commit e632116bee
2 changed files with 130 additions and 109 deletions

View file

@ -1,4 +1,4 @@
/* $Id: unicode.c,v 1.13 2000/02/05 16:08:49 ekohl Exp $ /* $Id: unicode.c,v 1.14 2000/02/19 19:31:41 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -291,34 +291,40 @@ RtlCompareString (
IN BOOLEAN CaseInsensitive IN BOOLEAN CaseInsensitive
) )
{ {
ULONG i; ULONG len1, len2;
CHAR c1, c2; PCHAR s1, s2;
PCHAR p1, p2; CHAR c1, c2;
if (String1->Length!=String2->Length) if (String1 && String2)
return String1->Length-String2->Length;
p1 = String1->Buffer;
p2 = String2->Buffer;
for (i = 0; i < String1->Length; i++)
{ {
if (CaseInsensitive == TRUE) len1 = String1->Length;
{ len2 = String2->Length;
c1 = RtlUpperChar (*p1); s1 = String1->Buffer;
c2 = RtlUpperChar (*p2); s2 = String2->Buffer;
}
else
{
c1 = *p1;
c2 = *p2;
}
if (c1 != c2) if (s1 && s2)
return c1-c2; {
if (CaseInsensitive)
p1++; {
p2++; while (1)
{
c1 = len1-- ? RtlUpperChar (*s1++) : 0;
c2 = len2-- ? RtlUpperChar (*s2++) : 0;
if (!c1 || !c2 || c1 != c2)
return c1 - c2;
}
}
else
{
while (1)
{
c1 = len1-- ? *s1++ : 0;
c2 = len2-- ? *s2++ : 0;
if (!c1 || !c2 || c1 != c2)
return c1 - c2;
}
}
}
} }
return 0; return 0;
@ -333,34 +339,40 @@ RtlCompareUnicodeString (
IN BOOLEAN CaseInsensitive IN BOOLEAN CaseInsensitive
) )
{ {
ULONG i; ULONG len1, len2;
WCHAR wc1, wc2; PWCHAR s1, s2;
PWCHAR pw1, pw2; WCHAR c1, c2;
if (String1->Length != String2->Length) if (String1 && String2)
return String1->Length-String2->Length;
pw1 = String1->Buffer;
pw2 = String2->Buffer;
for (i = 0; i < (String1->Length / sizeof(WCHAR)); i++)
{ {
if (CaseInsensitive == TRUE) len1 = String1->Length / sizeof(WCHAR);
{ len2 = String2->Length / sizeof(WCHAR);
wc1 = RtlUpcaseUnicodeChar (*pw1); s1 = String1->Buffer;
wc2 = RtlUpcaseUnicodeChar (*pw2); s2 = String2->Buffer;
}
else
{
wc1 = *pw1;
wc2 = *pw2;
}
if (wc1 != wc2) if (s1 && s2)
return wc1 - wc2; {
if (CaseInsensitive)
pw1++; {
pw2++; while (1)
{
c1 = len1-- ? RtlUpcaseUnicodeChar (*s1++) : 0;
c2 = len2-- ? RtlUpcaseUnicodeChar (*s2++) : 0;
if (!c1 || !c2 || c1 != c2)
return c1 - c2;
}
}
else
{
while (1)
{
c1 = len1-- ? *s1++ : 0;
c2 = len2-- ? *s2++ : 0;
if (!c1 || !c2 || c1 != c2)
return c1 - c2;
}
}
}
} }
return 0; return 0;

View file

@ -1,4 +1,4 @@
/* $Id: unicode.c,v 1.12 2000/01/11 01:16:50 ekohl Exp $ /* $Id: unicode.c,v 1.13 2000/02/19 19:31:18 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -273,44 +273,47 @@ RtlCharToInteger(IN PCSZ String, IN ULONG Base, IN OUT PULONG Value)
LONG LONG
STDCALL STDCALL
RtlCompareString ( RtlCompareString (
PSTRING String1, IN PSTRING String1,
PSTRING String2, IN PSTRING String2,
BOOLEAN CaseInsensitive IN BOOLEAN CaseInsensitive
) )
{ {
unsigned long i; ULONG len1, len2;
char c1, c2; PCHAR s1, s2;
CHAR c1, c2;
if (String1->Length != String2->Length) if (String1 && String2)
return String1->Length - String2->Length;
for (i=0; i<String1->Length; i++)
{ {
if (CaseInsensitive == TRUE) len1 = String1->Length;
{ len2 = String2->Length;
c1 = RtlUpperChar (*String1->Buffer); s1 = String1->Buffer;
c2 = RtlUpperChar (*String2->Buffer); s2 = String2->Buffer;
}
else
{
c1 = *String1->Buffer;
c2 = *String2->Buffer;
}
if (c1!=c2) if (s1 && s2)
{ {
String1->Buffer -= i; if (CaseInsensitive)
String2->Buffer -= i; {
return c1 - c2; while (1)
{
c1 = len1-- ? RtlUpperChar (*s1++) : 0;
c2 = len2-- ? RtlUpperChar (*s2++) : 0;
if (!c1 || !c2 || c1 != c2)
return c1 - c2;
}
}
else
{
while (1)
{
c1 = len1-- ? *s1++ : 0;
c2 = len2-- ? *s2++ : 0;
if (!c1 || !c2 || c1 != c2)
return c1 - c2;
}
}
} }
String1->Buffer++;
String2->Buffer++;
} }
String1->Buffer-=i;
String2->Buffer-=i;
return 0; return 0;
} }
@ -318,39 +321,45 @@ RtlCompareString (
LONG LONG
STDCALL STDCALL
RtlCompareUnicodeString ( RtlCompareUnicodeString (
PUNICODE_STRING String1, IN PUNICODE_STRING String1,
PUNICODE_STRING String2, IN PUNICODE_STRING String2,
BOOLEAN CaseInsensitive IN BOOLEAN CaseInsensitive
) )
{ {
unsigned long i; ULONG len1, len2;
WCHAR wc1, wc2; PWCHAR s1, s2;
PWCHAR pw1, pw2; WCHAR c1, c2;
if (String1->Length != String2->Length) if (String1 && String2)
return String1->Length - String2->Length;
pw1 = String1->Buffer;
pw2 = String2->Buffer;
for(i = 0; i < (String1->Length / sizeof(WCHAR)); i++)
{ {
if(CaseInsensitive == TRUE) len1 = String1->Length / sizeof(WCHAR);
{ len2 = String2->Length / sizeof(WCHAR);
wc1 = RtlUpcaseUnicodeChar (*pw1); s1 = String1->Buffer;
wc2 = RtlUpcaseUnicodeChar (*pw2); s2 = String2->Buffer;
}
else
{
wc1 = *pw1;
wc2 = *pw2;
}
if (wc1 != wc2) if (s1 && s2)
return wc1 - wc2; {
if (CaseInsensitive)
pw1++; {
pw2++; while (1)
{
c1 = len1-- ? RtlUpcaseUnicodeChar (*s1++) : 0;
c2 = len2-- ? RtlUpcaseUnicodeChar (*s2++) : 0;
if (!c1 || !c2 || c1 != c2)
return c1 - c2;
}
}
else
{
while (1)
{
c1 = len1-- ? *s1++ : 0;
c2 = len2-- ? *s2++ : 0;
if (!c1 || !c2 || c1 != c2)
return c1 - c2;
}
}
}
} }
return 0; return 0;