]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/String.c
MdePkg/BaseLib.h: state preprocessing conditions in comments after #endifs
[mirror_edk2.git] / MdePkg / Library / BaseLib / String.c
index 0b6a1957472fc169a59a741239cf7fe5c3372860..4151e0e7ac5866d992694c8e83fb78ffed3713dc 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
-  Unicode and ASCII string primatives.\r
+  Unicode and ASCII string primitives.\r
 \r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 \r
 #include "BaseLibInternals.h"\r
 \r
-#define QUOTIENT_MAX_UINTN_DIVIDED_BY_10      ((~((UINTN) 0)) / 10U)\r
-#define REMAINDER_MAX_UINTN_DIVIDED_BY_10    ((~((UINTN) 0)) % 10U)\r
-\r
-\r
-#define QUOTIENT_MAX_UINTN_DIVIDED_BY_16       ((~((UINTN) 0)) / 16U)\r
-#define REMAINDER_MAX_UINTN_DIVIDED_BY_16     ((~((UINTN) 0)) % 16U)\r
-\r
-#define QUOTIENT_MAX_UINT64_DIVIDED_BY_10      ((~((UINT64) 0)) / 10U)\r
-#define REMAINDER_MAX_UINT64_DIVIDED_BY_10    ((~((UINT64) 0)) % 10U)\r
-\r
-#define QUOTIENT_MAX_UINT64_DIVIDED_BY_16      ((~((UINT64) 0)) / 16U)\r
-#define REMAINDER_MAX_UINT64_DIVIDED_BY_16    ((~((UINT64) 0)) % 16U)\r
+#ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
 \r
 /**\r
+  [ATTENTION] This function will be deprecated for security reason.\r
+\r
   Copies one Null-terminated Unicode string to another Null-terminated Unicode\r
   string and returns the new Unicode string.\r
 \r
@@ -80,6 +71,8 @@ StrCpy (
 }\r
 \r
 /**\r
+  [ATTENTION] This function will be deprecated for security reason.\r
+\r
   Copies up to a specified length from one Null-terminated Unicode string  to \r
   another Null-terminated Unicode string and returns the new Unicode string.\r
 \r
@@ -149,6 +142,7 @@ StrnCpy (
   ZeroMem (Destination, Length * sizeof (*Destination));\r
   return ReturnValue;\r
 }\r
+#endif\r
 \r
 /**\r
   Returns the length of a Null-terminated Unicode string.\r
@@ -321,6 +315,7 @@ StrnCmp (
   }\r
 \r
   while ((*FirstString != L'\0') &&\r
+         (*SecondString != L'\0') &&\r
          (*FirstString == *SecondString) &&\r
          (Length > 1)) {\r
     FirstString++;\r
@@ -331,7 +326,11 @@ StrnCmp (
   return *FirstString - *SecondString;\r
 }\r
 \r
+#ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
+\r
 /**\r
+  [ATTENTION] This function will be deprecated for security reason.\r
+\r
   Concatenates one Null-terminated Unicode string to another Null-terminated\r
   Unicode string, and returns the concatenated Unicode string.\r
 \r
@@ -381,6 +380,8 @@ StrCat (
 }\r
 \r
 /**\r
+  [ATTENTION] This function will be deprecated for security reason.\r
+\r
   Concatenates up to a specified length one Null-terminated Unicode to the end \r
   of another Null-terminated Unicode string, and returns the concatenated \r
   Unicode string.\r
@@ -439,6 +440,7 @@ StrnCat (
   ASSERT (StrSize (Destination) != 0);\r
   return Destination;\r
 }\r
+#endif\r
 \r
 /**\r
   Returns the first occurrence of a Null-terminated Unicode sub-string\r
@@ -584,7 +586,7 @@ InternalHexCharToUintn (
     return Char - L'0';\r
   }\r
 \r
-  return (UINTN) (10 + InternalCharToUpper (Char) - L'A');\r
+  return (10 + InternalCharToUpper (Char) - L'A');\r
 }\r
 \r
 /**\r
@@ -636,7 +638,7 @@ InternalIsHexaDecimalDigitCharacter (
   If String has no pad spaces or valid decimal digits,\r
   then 0 is returned.\r
   If the number represented by String overflows according\r
-  to the range defined by UINTN, then ASSERT().\r
+  to the range defined by UINTN, then MAX_UINTN is returned.\r
 \r
   If PcdMaximumUnicodeStringLength is not zero, and String contains\r
   more than PcdMaximumUnicodeStringLength Unicode characters, not including\r
@@ -654,43 +656,8 @@ StrDecimalToUintn (
   )\r
 {\r
   UINTN     Result;\r
-  \r
-  //\r
-  // ASSERT String is less long than PcdMaximumUnicodeStringLength.\r
-  // Length tests are performed inside StrLen().\r
-  //\r
-  ASSERT (StrSize (String) != 0);\r
-\r
-  //\r
-  // Ignore the pad spaces (space or tab)\r
-  //\r
-  while ((*String == L' ') || (*String == L'\t')) {\r
-    String++;\r
-  }\r
-\r
-  //\r
-  // Ignore leading Zeros after the spaces\r
-  //\r
-  while (*String == L'0') {\r
-    String++;\r
-  }\r
-\r
-  Result = 0;\r
-\r
-  while (InternalIsDecimalDigitCharacter (*String)) {\r
-    //\r
-    // If the number represented by String overflows according \r
-    // to the range defined by UINTN, then ASSERT().\r
-    //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_10) ||\r
-      ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_10) &&\r
-      (*String - L'0') <= REMAINDER_MAX_UINTN_DIVIDED_BY_10)\r
-      );\r
 \r
-    Result = Result * 10 + (*String - L'0');\r
-    String++;\r
-  }\r
-  \r
+  StrDecimalToUintnS (String, (CHAR16 **) NULL, &Result);\r
   return Result;\r
 }\r
 \r
@@ -718,7 +685,7 @@ StrDecimalToUintn (
   If String has no pad spaces or valid decimal digits,\r
   then 0 is returned.\r
   If the number represented by String overflows according\r
-  to the range defined by UINT64, then ASSERT().\r
+  to the range defined by UINT64, then MAX_UINT64 is returned.\r
 \r
   If PcdMaximumUnicodeStringLength is not zero, and String contains\r
   more than PcdMaximumUnicodeStringLength Unicode characters, not including\r
@@ -737,42 +704,7 @@ StrDecimalToUint64 (
 {\r
   UINT64     Result;\r
   \r
-  //\r
-  // ASSERT String is less long than PcdMaximumUnicodeStringLength.\r
-  // Length tests are performed inside StrLen().\r
-  //\r
-  ASSERT (StrSize (String) != 0);\r
-\r
-  //\r
-  // Ignore the pad spaces (space or tab)\r
-  //\r
-  while ((*String == L' ') || (*String == L'\t')) {\r
-    String++;\r
-  }\r
-\r
-  //\r
-  // Ignore leading Zeros after the spaces\r
-  //\r
-  while (*String == L'0') {\r
-    String++;\r
-  }\r
-\r
-  Result = 0;\r
-\r
-  while (InternalIsDecimalDigitCharacter (*String)) {\r
-    //\r
-    // If the number represented by String overflows according \r
-    // to the range defined by UINTN, then ASSERT().\r
-    //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_10) || \r
-      ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_10) && \r
-      (*String - L'0') <= REMAINDER_MAX_UINT64_DIVIDED_BY_10)\r
-      );\r
-\r
-    Result = MultU64x32 (Result, 10) + (*String - L'0');\r
-    String++;\r
-  }\r
-  \r
+  StrDecimalToUint64S (String, (CHAR16 **) NULL, &Result);\r
   return Result;\r
 }\r
 \r
@@ -800,7 +732,7 @@ StrDecimalToUint64 (
   If String has no leading pad spaces, leading zeros or valid hexadecimal digits,\r
   then zero is returned.\r
   If the number represented by String overflows according to the range defined by\r
-  UINTN, then ASSERT().\r
+  UINTN, then MAX_UINTN is returned.\r
 \r
   If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
   PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,\r
@@ -819,52 +751,7 @@ StrHexToUintn (
 {\r
   UINTN     Result;\r
 \r
-  //\r
-  // ASSERT String is less long than PcdMaximumUnicodeStringLength.\r
-  // Length tests are performed inside StrLen().\r
-  //\r
-  ASSERT (StrSize (String) != 0);\r
-  \r
-  //\r
-  // Ignore the pad spaces (space or tab) \r
-  //\r
-  while ((*String == L' ') || (*String == L'\t')) {\r
-    String++;\r
-  }\r
-\r
-  //\r
-  // Ignore leading Zeros after the spaces\r
-  //\r
-  while (*String == L'0') {\r
-    String++;\r
-  }\r
-\r
-  if (InternalCharToUpper (*String) == L'X') {\r
-    if (*(String - 1) != L'0') {\r
-      return 0;\r
-    }\r
-    //\r
-    // Skip the 'X'\r
-    //\r
-    String++;\r
-  }\r
-\r
-  Result = 0;\r
-  \r
-  while (InternalIsHexaDecimalDigitCharacter (*String)) {\r
-    //\r
-    // If the Hex Number represented by String overflows according \r
-    // to the range defined by UINTN, then ASSERT().\r
-    //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_16) ||\r
-      ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_16) && \r
-      (InternalHexCharToUintn (*String) <= REMAINDER_MAX_UINTN_DIVIDED_BY_16))\r
-      );\r
-\r
-    Result = (Result << 4) + InternalHexCharToUintn (*String);\r
-    String++;\r
-  }\r
-\r
+  StrHexToUintnS (String, (CHAR16 **) NULL, &Result);\r
   return Result;\r
 }\r
 \r
@@ -893,7 +780,7 @@ StrHexToUintn (
   If String has no leading pad spaces, leading zeros or valid hexadecimal digits,\r
   then zero is returned.\r
   If the number represented by String overflows according to the range defined by\r
-  UINT64, then ASSERT().\r
+  UINT64, then MAX_UINT64 is returned.\r
 \r
   If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
   PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,\r
@@ -912,54 +799,7 @@ StrHexToUint64 (
 {\r
   UINT64    Result;\r
 \r
-  //\r
-  // ASSERT String is less long than PcdMaximumUnicodeStringLength.\r
-  // Length tests are performed inside StrLen().\r
-  //\r
-  ASSERT (StrSize (String) != 0);\r
-  \r
-  //\r
-  // Ignore the pad spaces (space or tab) \r
-  //\r
-  while ((*String == L' ') || (*String == L'\t')) {\r
-    String++;\r
-  }\r
-\r
-  //\r
-  // Ignore leading Zeros after the spaces\r
-  //\r
-  while (*String == L'0') {\r
-    String++;\r
-  }\r
-\r
-  if (InternalCharToUpper (*String) == L'X') {\r
-    ASSERT (*(String - 1) == L'0');\r
-    if (*(String - 1) != L'0') {\r
-      return 0;\r
-    }\r
-    //\r
-    // Skip the 'X'\r
-    //\r
-    String++;\r
-  }\r
-\r
-  Result = 0;\r
-  \r
-  while (InternalIsHexaDecimalDigitCharacter (*String)) {\r
-    //\r
-    // If the Hex Number represented by String overflows according \r
-    // to the range defined by UINTN, then ASSERT().\r
-    //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_16)|| \r
-      ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_16) && \r
-      (InternalHexCharToUintn (*String) <= REMAINDER_MAX_UINT64_DIVIDED_BY_16))\r
-      );\r
-\r
-    Result = LShiftU64 (Result, 4);\r
-    Result = Result + InternalHexCharToUintn (*String);\r
-    String++;\r
-  }\r
-\r
+  StrHexToUint64S (String, (CHAR16 **) NULL, &Result);\r
   return Result;\r
 }\r
 \r
@@ -1011,7 +851,11 @@ InternalAsciiIsHexaDecimalDigitCharacter (
     (Char >= 'a' && Char <= 'f'));\r
 }\r
 \r
+#ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
+\r
 /**\r
+  [ATTENTION] This function is deprecated for security reason.\r
+\r
   Convert a Null-terminated Unicode string to a Null-terminated\r
   ASCII string and returns the ASCII string.\r
 \r
@@ -1019,6 +863,9 @@ InternalAsciiIsHexaDecimalDigitCharacter (
   to the ASCII string Destination by copying the lower 8 bits of\r
   each Unicode character. It returns Destination.\r
 \r
+  The caller is responsible to make sure Destination points to a buffer with size\r
+  equal or greater than ((StrLen (Source) + 1) * sizeof (CHAR8)) in bytes.\r
+\r
   If any Unicode characters in Source contain non-zero value in\r
   the upper 8 bits, then ASSERT().\r
 \r
@@ -1061,7 +908,7 @@ UnicodeStrToAsciiStr (
   //\r
   // Source and Destination should not overlap\r
   //\r
-  ASSERT ((UINTN) ((CHAR16 *) Destination -  Source) > StrLen (Source));\r
+  ASSERT ((UINTN) (Destination - (CHAR8 *) Source) >= StrSize (Source));\r
   ASSERT ((UINTN) ((CHAR8 *) Source - Destination) > StrLen (Source));\r
 \r
 \r
@@ -1086,8 +933,9 @@ UnicodeStrToAsciiStr (
   return ReturnValue;\r
 }\r
 \r
-\r
 /**\r
+  [ATTENTION] This function will be deprecated for security reason.\r
+\r
   Copies one Null-terminated ASCII string to another Null-terminated ASCII\r
   string and returns the new ASCII string.\r
 \r
@@ -1137,6 +985,8 @@ AsciiStrCpy (
 }\r
 \r
 /**\r
+  [ATTENTION] This function will be deprecated for security reason.\r
+\r
   Copies up to a specified length one Null-terminated ASCII string to another \r
   Null-terminated ASCII string and returns the new ASCII string.\r
 \r
@@ -1202,6 +1052,7 @@ AsciiStrnCpy (
   ZeroMem (Destination, Length * sizeof (*Destination));\r
   return ReturnValue;\r
 }\r
+#endif\r
 \r
 /**\r
   Returns the length of a Null-terminated ASCII string.\r
@@ -1360,7 +1211,7 @@ InternalAsciiHexCharToUintn (
     return Char - '0';\r
   }\r
 \r
-  return (UINTN) (10 + InternalBaseLibAsciiToUpper (Char) - 'A');\r
+  return (10 + InternalBaseLibAsciiToUpper (Char) - 'A');\r
 }\r
 \r
 \r
@@ -1474,6 +1325,7 @@ AsciiStrnCmp (
   }\r
 \r
   while ((*FirstString != '\0') &&\r
+         (*SecondString != '\0') &&\r
          (*FirstString == *SecondString) &&\r
          (Length > 1)) {\r
     FirstString++;\r
@@ -1483,7 +1335,11 @@ AsciiStrnCmp (
   return *FirstString - *SecondString;\r
 }\r
 \r
+#ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
+\r
 /**\r
+  [ATTENTION] This function will be deprecated for security reason.\r
+\r
   Concatenates one Null-terminated ASCII string to another Null-terminated\r
   ASCII string, and returns the concatenated ASCII string.\r
 \r
@@ -1528,6 +1384,8 @@ AsciiStrCat (
 }\r
 \r
 /**\r
+  [ATTENTION] This function will be deprecated for security reason.\r
+\r
   Concatenates up to a specified length one Null-terminated ASCII string to \r
   the end of another Null-terminated ASCII string, and returns the \r
   concatenated ASCII string.\r
@@ -1584,6 +1442,7 @@ AsciiStrnCat (
   ASSERT (AsciiStrSize (Destination) != 0);\r
   return Destination;\r
 }\r
+#endif\r
 \r
 /**\r
   Returns the first occurrence of a Null-terminated ASCII sub-string\r
@@ -1672,7 +1531,7 @@ AsciiStrStr (
   If String has only pad spaces, then 0 is returned.\r
   If String has no pad spaces or valid decimal digits, then 0 is returned.\r
   If the number represented by String overflows according to the range defined by\r
-  UINTN, then ASSERT().\r
+  UINTN, then MAX_UINTN is returned.\r
   If String is NULL, then ASSERT().\r
   If PcdMaximumAsciiStringLength is not zero, and String contains more than\r
   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
@@ -1691,41 +1550,7 @@ AsciiStrDecimalToUintn (
 {\r
   UINTN     Result;\r
   \r
-  //\r
-  // ASSERT Strings is less long than PcdMaximumAsciiStringLength\r
-  //\r
-  ASSERT (AsciiStrSize (String) != 0);\r
-\r
-  //\r
-  // Ignore the pad spaces (space or tab)\r
-  //\r
-  while ((*String == ' ') || (*String == '\t' )) {\r
-    String++;\r
-  }\r
-\r
-  //\r
-  // Ignore leading Zeros after the spaces\r
-  //\r
-  while (*String == '0') {\r
-    String++;\r
-  }\r
-\r
-  Result = 0;\r
-\r
-  while (InternalAsciiIsDecimalDigitCharacter (*String)) {\r
-    //\r
-    // If the number represented by String overflows according \r
-    // to the range defined by UINTN, then ASSERT().\r
-    //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_10) ||\r
-      ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_10) && \r
-      (*String - '0') <= REMAINDER_MAX_UINTN_DIVIDED_BY_10)\r
-      );\r
-\r
-    Result = Result * 10 + (*String - '0');\r
-    String++;\r
-  }\r
-  \r
+  AsciiStrDecimalToUintnS (String, (CHAR8 **) NULL, &Result);\r
   return Result;\r
 }\r
 \r
@@ -1749,7 +1574,7 @@ AsciiStrDecimalToUintn (
   If String has only pad spaces, then 0 is returned.\r
   If String has no pad spaces or valid decimal digits, then 0 is returned.\r
   If the number represented by String overflows according to the range defined by\r
-  UINT64, then ASSERT().\r
+  UINT64, then MAX_UINT64 is returned.\r
   If String is NULL, then ASSERT().\r
   If PcdMaximumAsciiStringLength is not zero, and String contains more than\r
   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
@@ -1768,41 +1593,7 @@ AsciiStrDecimalToUint64 (
 {\r
   UINT64     Result;\r
   \r
-  //\r
-  // ASSERT Strings is less long than PcdMaximumAsciiStringLength\r
-  //\r
-  ASSERT (AsciiStrSize (String) != 0);\r
-\r
-  //\r
-  // Ignore the pad spaces (space or tab)\r
-  //\r
-  while ((*String == ' ') || (*String == '\t' )) {\r
-    String++;\r
-  }\r
-\r
-  //\r
-  // Ignore leading Zeros after the spaces\r
-  //\r
-  while (*String == '0') {\r
-    String++;\r
-  }\r
-\r
-  Result = 0;\r
-\r
-  while (InternalAsciiIsDecimalDigitCharacter (*String)) {\r
-    //\r
-    // If the number represented by String overflows according \r
-    // to the range defined by UINTN, then ASSERT().\r
-    //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_10) || \r
-      ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_10) && \r
-      (*String - '0') <= REMAINDER_MAX_UINT64_DIVIDED_BY_10)\r
-      );\r
-\r
-    Result = MultU64x32 (Result, 10) + (*String - '0');\r
-    String++;\r
-  }\r
-  \r
+  AsciiStrDecimalToUint64S (String, (CHAR8 **) NULL, &Result);\r
   return Result;\r
 }\r
 \r
@@ -1829,7 +1620,7 @@ AsciiStrDecimalToUint64 (
   0 is returned.\r
 \r
   If the number represented by String overflows according to the range defined by UINTN,\r
-  then ASSERT().\r
+  then MAX_UINTN is returned.\r
   If String is NULL, then ASSERT().\r
   If PcdMaximumAsciiStringLength is not zero,\r
   and String contains more than PcdMaximumAsciiStringLength ASCII characters not including\r
@@ -1848,52 +1639,7 @@ AsciiStrHexToUintn (
 {\r
   UINTN     Result;\r
 \r
-  //\r
-  // ASSERT Strings is less long than PcdMaximumAsciiStringLength\r
-  //\r
-  ASSERT (AsciiStrSize (String) != 0);\r
-  \r
-  //\r
-  // Ignore the pad spaces (space or tab) \r
-  //\r
-  while ((*String == ' ') || (*String == '\t' )) {\r
-    String++;\r
-  }\r
-\r
-  //\r
-  // Ignore leading Zeros after the spaces\r
-  //\r
-  while (*String == '0') {\r
-    String++;\r
-  }\r
-\r
-  if (InternalBaseLibAsciiToUpper (*String) == 'X') {\r
-    ASSERT (*(String - 1) == '0');\r
-    if (*(String - 1) != '0') {\r
-      return 0;\r
-    }\r
-    //\r
-    // Skip the 'X'\r
-    //\r
-    String++;\r
-  }\r
-\r
-  Result = 0;\r
-  \r
-  while (InternalAsciiIsHexaDecimalDigitCharacter (*String)) {\r
-    //\r
-    // If the Hex Number represented by String overflows according \r
-    // to the range defined by UINTN, then ASSERT().\r
-    //\r
-     ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_16) ||\r
-       ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_16) && \r
-       (InternalAsciiHexCharToUintn (*String) <= REMAINDER_MAX_UINTN_DIVIDED_BY_16))\r
-       );\r
-\r
-    Result = (Result << 4) + InternalAsciiHexCharToUintn (*String);\r
-    String++;\r
-  }\r
-\r
+  AsciiStrHexToUintnS (String, (CHAR8 **) NULL, &Result);\r
   return Result;\r
 }\r
 \r
@@ -1921,7 +1667,7 @@ AsciiStrHexToUintn (
   0 is returned.\r
 \r
   If the number represented by String overflows according to the range defined by UINT64,\r
-  then ASSERT().\r
+  then MAX_UINT64 is returned.\r
   If String is NULL, then ASSERT().\r
   If PcdMaximumAsciiStringLength is not zero,\r
   and String contains more than PcdMaximumAsciiStringLength ASCII characters not including\r
@@ -1940,61 +1686,15 @@ AsciiStrHexToUint64 (
 {\r
   UINT64    Result;\r
 \r
-  //\r
-  // ASSERT Strings is less long than PcdMaximumAsciiStringLength\r
-  //\r
-  ASSERT (AsciiStrSize (String) != 0);\r
-  \r
-  //\r
-  // Ignore the pad spaces (space or tab) and leading Zeros\r
-  //\r
-  //\r
-  // Ignore the pad spaces (space or tab) \r
-  //\r
-  while ((*String == ' ') || (*String == '\t' )) {\r
-    String++;\r
-  }\r
-\r
-  //\r
-  // Ignore leading Zeros after the spaces\r
-  //\r
-  while (*String == '0') {\r
-    String++;\r
-  }\r
-\r
-  if (InternalBaseLibAsciiToUpper (*String) == 'X') {\r
-    ASSERT (*(String - 1) == '0');\r
-    if (*(String - 1) != '0') {\r
-      return 0;\r
-    }\r
-    //\r
-    // Skip the 'X'\r
-    //\r
-    String++;\r
-  }\r
-\r
-  Result = 0;\r
-  \r
-  while (InternalAsciiIsHexaDecimalDigitCharacter (*String)) {\r
-    //\r
-    // If the Hex Number represented by String overflows according \r
-    // to the range defined by UINTN, then ASSERT().\r
-    //\r
-    ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_16) ||\r
-      ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_16) && \r
-      (InternalAsciiHexCharToUintn (*String) <= REMAINDER_MAX_UINT64_DIVIDED_BY_16))\r
-      );\r
-\r
-    Result = LShiftU64 (Result, 4);\r
-    Result = Result + InternalAsciiHexCharToUintn (*String);\r
-    String++;\r
-  }\r
-\r
+  AsciiStrHexToUint64S (String, (CHAR8 **) NULL, &Result);\r
   return Result;\r
 }\r
 \r
+#ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
 \r
 /**\r
+  [ATTENTION] This function is deprecated for security reason.\r
+\r
   Convert one Null-terminated ASCII string to a Null-terminated\r
   Unicode string and returns the Unicode string.\r
 \r
@@ -2041,9 +1741,9 @@ AsciiStrToUnicodeStr (
   // Source and Destination should not overlap\r
   //\r
   ASSERT ((UINTN) ((CHAR8 *) Destination - Source) > AsciiStrLen (Source));\r
-  ASSERT ((UINTN) (Source - (CHAR8 *) Destination) > (AsciiStrLen (Source) * sizeof (CHAR16)));\r
+  ASSERT ((UINTN) (Source - (CHAR8 *) Destination) >= (AsciiStrSize (Source) * sizeof (CHAR16)));\r
+\r
 \r
\r
   ReturnValue = Destination;\r
   while (*Source != '\0') {\r
     *(Destination++) = (CHAR16) *(Source++);\r
@@ -2061,6 +1761,8 @@ AsciiStrToUnicodeStr (
   return ReturnValue;\r
 }\r
 \r
+#endif\r
+\r
 /**\r
   Converts an 8-bit value to an 8-bit BCD value.\r
 \r