From 2ca7eca448e914c5c21cac5ba3832e09b4b163e8 Mon Sep 17 00:00:00 2001 From: niruiyu Date: Thu, 26 Aug 2010 03:15:23 +0000 Subject: [PATCH] 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 --- .../Universal/BdsDxe/FrontPage.c | 56 ++++++------------- 1 file 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; } -- 2.39.2