Fix a bug in GetOptionalStringByIndex() that doesn't handle the case when Index == 0.

Code is re-organized to be more readable and simpler.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10823 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
niruiyu 2010-08-26 03:15:23 +00:00
parent 00dbccf2d5
commit 2ca7eca448
1 changed files with 17 additions and 41 deletions

View File

@ -663,51 +663,27 @@ GetOptionalStringByIndex (
OUT CHAR16 **String OUT CHAR16 **String
) )
{ {
UINT8 StrNum; UINTN StrSize;
UINTN CurrentStrLen;
CHAR8* CharInStr;
EFI_STATUS Status;
StrNum = 0; if (Index == 0) {
Status = EFI_NOT_FOUND; *String = AllocateZeroPool (sizeof (CHAR16));
CharInStr = OptionalStrStart; return EFI_SUCCESS;
if (Index != 1) {
CurrentStrLen = 0;
//
// look for the two consecutive zeros, check the string limit by the way.
//
while (*CharInStr != 0 || *(CharInStr+1) != 0) {
if (*CharInStr == 0) {
StrNum += 1;
CharInStr++;
} }
if (StrNum == Index) { StrSize = 0;
Status = EFI_SUCCESS; do {
break; Index--;
} OptionalStrStart += StrSize;
StrSize = AsciiStrSize (OptionalStrStart);
} while (OptionalStrStart[StrSize] != 0 && Index != 0);
CurrentStrLen = AsciiStrLen(CharInStr); if (Index != 0) {
//
// forward the pointer
//
OptionalStrStart = CharInStr;
CharInStr += CurrentStrLen;
}
if (EFI_ERROR (Status)) {
*String = GetStringById (STRING_TOKEN (STR_MISSING_STRING)); *String = GetStringById (STRING_TOKEN (STR_MISSING_STRING));
return Status;
}
} else { } else {
CurrentStrLen = AsciiStrLen(CharInStr); *String = AllocatePool (StrSize * sizeof (CHAR16));
AsciiStrToUnicodeStr (OptionalStrStart, *String);
} }
*String = AllocatePool((CurrentStrLen + 1)*sizeof(CHAR16));
AsciiStrToUnicodeStr(OptionalStrStart, *String);
return EFI_SUCCESS; return EFI_SUCCESS;
} }