]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Fix a bug in GetOptionalStringByIndex() that doesn't handle the case when Index ...
authorniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 26 Aug 2010 03:15:23 +0000 (03:15 +0000)
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 26 Aug 2010 03:15:23 +0000 (03:15 +0000)
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

IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c

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