]> git.proxmox.com Git - mirror_edk2.git/commitdiff
When transfer from Unicode to hex number, current code only consider the 0-9 case...
authorydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Sun, 1 Apr 2012 07:28:09 +0000 (07:28 +0000)
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Sun, 1 Apr 2012 07:28:09 +0000 (07:28 +0000)
Signed-off-by: Dong Eric <eric.dong@intel.com>
Reviewed-by: Ni Ruiyu <ruiyu.ni@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13159 6f19259b-4bc3-4df7-8a09-765794883524

IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c

index 904e968db95f6f48951d343e5dd31a2ca833b513..15a47e1917ea98893f35b887a43ad1967b43b890 100644 (file)
@@ -480,6 +480,30 @@ StrSizeEx (
   return (Length + 1) * sizeof (*String);\r
 }\r
 \r
+/**\r
+  Convert a single character to number.\r
+  It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'\r
+  \r
+  @param Char    The input char which need to change to a hex number.\r
+  \r
+**/\r
+UINTN\r
+CharToUint (\r
+  IN CHAR16                           Char\r
+  )\r
+{\r
+  if ((Char >= L'0') && (Char <= L'9')) {\r
+    return (UINTN) (Char - L'0');\r
+  }\r
+\r
+  if ((Char >= L'A') && (Char <= L'F')) {\r
+    return (UINTN) (Char - L'A' + 0xA);\r
+  }\r
+\r
+  ASSERT (FALSE);\r
+  return 0;\r
+}\r
+\r
 /**\r
   Build the boot#### or driver#### option from the VariableName, the\r
   build boot#### or driver#### will also be linked to BdsCommonOptionList.\r
@@ -613,11 +637,11 @@ BdsLibVariableToOption (
   // Unicode stream to ASCII without any loss in meaning.\r
   //\r
   if (*VariableName == 'B') {\r
-    NumOff = (UINT8) (sizeof (L"Boot") / sizeof(CHAR16) - 1);\r
-    Option->BootCurrent = (UINT16) ((VariableName[NumOff]  -'0') * 0x1000);\r
-    Option->BootCurrent = (UINT16) (Option->BootCurrent + ((VariableName[NumOff+1]-'0') * 0x100));\r
-    Option->BootCurrent = (UINT16) (Option->BootCurrent +  ((VariableName[NumOff+2]-'0') * 0x10));\r
-    Option->BootCurrent = (UINT16) (Option->BootCurrent + ((VariableName[NumOff+3]-'0')));\r
+    NumOff = (UINT8) (sizeof (L"Boot") / sizeof (CHAR16) - 1);\r
+    Option->BootCurrent = (UINT16) (CharToUint (VariableName[NumOff+0]) * 0x1000) \r
+               + (UINT16) (CharToUint (VariableName[NumOff+1]) * 0x100)\r
+               + (UINT16) (CharToUint (VariableName[NumOff+2]) * 0x10)\r
+               + (UINT16) (CharToUint (VariableName[NumOff+3]) * 0x1);\r
   }\r
   //\r
   // Insert active entry to BdsDeviceList\r