Fix bugs in StrStr() and AsciiStrStr().

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8261 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
rsun3 2009-05-08 05:22:17 +00:00
parent 130a2eecc4
commit 62e71e2fbe
1 changed files with 18 additions and 19 deletions

View File

@ -478,29 +478,29 @@ StrStr (
ASSERT (StrSize (String) != 0); ASSERT (StrSize (String) != 0);
ASSERT (StrSize (SearchString) != 0); ASSERT (StrSize (SearchString) != 0);
while (*String != '\0') { if (*SearchString == L'\0') {
return NULL;
}
while (*String != L'\0') {
SearchStringTmp = SearchString; SearchStringTmp = SearchString;
FirstMatch = String; FirstMatch = String;
while ((*String == *SearchStringTmp) while ((*String == *SearchStringTmp)
&& (*SearchStringTmp != '\0') && (*String != L'\0')) {
&& (*String != '\0')) {
String++; String++;
SearchStringTmp++; SearchStringTmp++;
} }
if (*SearchStringTmp == '\0') { if (*SearchStringTmp == L'\0') {
return (CHAR16 *) FirstMatch; return (CHAR16 *) FirstMatch;
} }
if (SearchStringTmp == SearchString) { if (*String == L'\0') {
// return NULL;
// If no character from SearchString match,
// move the pointer to the String under search
// by one character.
//
String++;
} }
String = FirstMatch + 1;
} }
return NULL; return NULL;
@ -1616,12 +1616,15 @@ AsciiStrStr (
ASSERT (AsciiStrSize (String) != 0); ASSERT (AsciiStrSize (String) != 0);
ASSERT (AsciiStrSize (SearchString) != 0); ASSERT (AsciiStrSize (SearchString) != 0);
if (*SearchString == '\0') {
return NULL;
}
while (*String != '\0') { while (*String != '\0') {
SearchStringTmp = SearchString; SearchStringTmp = SearchString;
FirstMatch = String; FirstMatch = String;
while ((*String == *SearchStringTmp) while ((*String == *SearchStringTmp)
&& (*SearchStringTmp != '\0')
&& (*String != '\0')) { && (*String != '\0')) {
String++; String++;
SearchStringTmp++; SearchStringTmp++;
@ -1631,15 +1634,11 @@ AsciiStrStr (
return (CHAR8 *) FirstMatch; return (CHAR8 *) FirstMatch;
} }
if (SearchStringTmp == SearchString) { if (*String == '\0') {
// return NULL;
// If no character from SearchString match,
// move the pointer to the String under search
// by one character.
//
String++;
} }
String = FirstMatch + 1;
} }
return NULL; return NULL;