summaryrefslogtreecommitdiff
path: root/IntelFrameworkModulePkg
diff options
context:
space:
mode:
authorniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>2010-08-26 03:15:23 +0000
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>2010-08-26 03:15:23 +0000
commit2ca7eca448e914c5c21cac5ba3832e09b4b163e8 (patch)
tree4c340ab4eac2054671ca943f9ed1dac0e2586617 /IntelFrameworkModulePkg
parent00dbccf2d5121545a89d88b04b408ebbb75aad0f (diff)
downloadedk2-platforms-2ca7eca448e914c5c21cac5ba3832e09b4b163e8.tar.xz
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
Diffstat (limited to 'IntelFrameworkModulePkg')
-rw-r--r--IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c56
1 files changed, 16 insertions, 40 deletions
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c b/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
index 7de4551b97..62ba394843 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
@@ -663,51 +663,27 @@ GetOptionalStringByIndex (
OUT CHAR16 **String
)
{
- UINT8 StrNum;
- UINTN CurrentStrLen;
- CHAR8* CharInStr;
- EFI_STATUS Status;
+ UINTN StrSize;
- StrNum = 0;
- Status = EFI_NOT_FOUND;
- CharInStr = OptionalStrStart;
+ if (Index == 0) {
+ *String = AllocateZeroPool (sizeof (CHAR16));
+ 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) {
- Status = EFI_SUCCESS;
- break;
- }
-
- CurrentStrLen = AsciiStrLen(CharInStr);
-
- //
- // forward the pointer
- //
- OptionalStrStart = CharInStr;
- CharInStr += CurrentStrLen;
- }
-
- if (EFI_ERROR (Status)) {
- *String = GetStringById (STRING_TOKEN (STR_MISSING_STRING));
- return Status;
- }
+ StrSize = 0;
+ do {
+ Index--;
+ OptionalStrStart += StrSize;
+ StrSize = AsciiStrSize (OptionalStrStart);
+ } while (OptionalStrStart[StrSize] != 0 && Index != 0);
+
+ if (Index != 0) {
+ *String = GetStringById (STRING_TOKEN (STR_MISSING_STRING));
} else {
- CurrentStrLen = AsciiStrLen(CharInStr);
+ *String = AllocatePool (StrSize * sizeof (CHAR16));
+ AsciiStrToUnicodeStr (OptionalStrStart, *String);
}
- *String = AllocatePool((CurrentStrLen + 1)*sizeof(CHAR16));
- AsciiStrToUnicodeStr(OptionalStrStart, *String);
-
return EFI_SUCCESS;
}