]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. Add conformance checking to ensure the input & output string are well-defined.
authorqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 1 Feb 2008 15:02:05 +0000 (15:02 +0000)
committerqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 1 Feb 2008 15:02:05 +0000 (15:02 +0000)
2. Adjust the return value of UnicodeStrToAsciiStr() & AsciiStrToUnicodeStr () to be the original destination string to follow MdeLib spec.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4653 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Library/BaseLib/String.c

index 639a55688a9abb7169d8ea14e57387045d5630e0..9fca9680748490729dfc19c7870ad4cb5045f61e 100644 (file)
@@ -434,8 +434,8 @@ StrnCat (
   or String contains more than PcdMaximumUnicodeStringLength Unicode \r
   characters not including the Null-terminator, then ASSERT().\r
 \r
-  @param  String                                 Pointer to a Null-terminated Unicode string.\r
-  @param  SearchString Pointer to a Null-terminated Unicode string to search for.\r
+  @param  String                  Pointer to a Null-terminated Unicode string.\r
+  @param  SearchString  Pointer to a Null-terminated Unicode string to search for.\r
 \r
   @retval NULL            If the SearchString does not appear in String.\r
   @retval !NULL           If there is a match.\r
@@ -444,33 +444,19 @@ StrnCat (
 CHAR16 *\r
 EFIAPI\r
 StrStr (\r
-  IN      CONST CHAR16               *String,\r
-  IN      CONST CHAR16               *SearchString\r
+  IN      CONST CHAR16                *String,\r
+  IN      CONST CHAR16                *SearchString\r
   )\r
 {\r
   CONST CHAR16 *FirstMatch;\r
   CONST CHAR16 *SearchStringTmp;\r
 \r
-  ASSERT (String != NULL);\r
-  ASSERT (((UINTN) String & 0x01) == 0);\r
-  ASSERT (SearchString != NULL);\r
-  ASSERT (((UINTN) SearchString & 0x01) == 0);\r
-\r
   //\r
-  // If PcdMaximumUnicodeStringLength is not zero,\r
-  // length of String should not more than PcdMaximumUnicodeStringLength\r
-  //\r
-  if (PcdGet32 (PcdMaximumUnicodeStringLength) != 0) {\r
-    ASSERT (StrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength));\r
-  }\r
-\r
-  //\r
-  // If PcdMaximumUnicodeStringLength is not zero,\r
-  // length of SearchString should not more than PcdMaximumUnicodeStringLength\r
+  // ASSERT both strings are less long than PcdMaximumUnicodeStringLength.\r
+  // Length tests are performed inside StrLen().\r
   //\r
-  if (PcdGet32 (PcdMaximumUnicodeStringLength) != 0) {\r
-    ASSERT (StrLen (SearchString) < PcdGet32 (PcdMaximumAsciiStringLength));\r
-  }\r
+  ASSERT (StrSize (String) != 0);\r
+  ASSERT (StrSize (SearchString) != 0);\r
 \r
   while (*String != '\0') {\r
     SearchStringTmp = SearchString;\r
@@ -633,7 +619,7 @@ InternalIsHexaDecimalDigitCharacter (
   more than PcdMaximumUnicodeStringLength Unicode characters not including \r
   the Null-terminator, then ASSERT().\r
 \r
-  @param  String                           Pointer to a Null-terminated Unicode string.\r
+  @param  String                Pointer to a Null-terminated Unicode string.\r
 \r
   @retval UINTN           \r
 \r
@@ -641,14 +627,16 @@ InternalIsHexaDecimalDigitCharacter (
 UINTN\r
 EFIAPI\r
 StrDecimalToUintn (\r
-  IN      CONST CHAR16               *String\r
+  IN      CONST CHAR16                *String\r
   )\r
 {\r
   UINTN     Result;\r
   \r
-  ASSERT (String != NULL);\r
-  ASSERT (((UINTN) String & 0x01) == 0);\r
-  ASSERT (StrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength));\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
@@ -713,7 +701,7 @@ StrDecimalToUintn (
   more than PcdMaximumUnicodeStringLength Unicode characters not including \r
   the Null-terminator, then ASSERT().\r
 \r
-  @param  String                           Pointer to a Null-terminated Unicode string.\r
+  @param  String                Pointer to a Null-terminated Unicode string.\r
 \r
   @retval UINT64           \r
 \r
@@ -721,14 +709,16 @@ StrDecimalToUintn (
 UINT64\r
 EFIAPI\r
 StrDecimalToUint64 (\r
-  IN      CONST CHAR16               *String\r
+  IN      CONST CHAR16                *String\r
   )\r
 {\r
   UINT64     Result;\r
   \r
-  ASSERT (String != NULL);\r
-  ASSERT (((UINTN) String & 0x01) == 0);\r
-  ASSERT (StrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength));\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
@@ -793,7 +783,7 @@ StrDecimalToUint64 (
   PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, \r
   then ASSERT().\r
 \r
-  @param  String                           Pointer to a Null-terminated Unicode string.\r
+  @param  String                Pointer to a Null-terminated Unicode string.\r
 \r
   @retval UINTN\r
 \r
@@ -801,14 +791,16 @@ StrDecimalToUint64 (
 UINTN\r
 EFIAPI\r
 StrHexToUintn (\r
-  IN      CONST CHAR16               *String\r
+  IN      CONST CHAR16                *String\r
   )\r
 {\r
   UINTN     Result;\r
 \r
-  ASSERT (String != NULL);\r
-  ASSERT (((UINTN) String & 0x01) == 0);\r
-  ASSERT (StrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength));\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
@@ -885,7 +877,7 @@ StrHexToUintn (
   PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, \r
   then ASSERT().\r
 \r
-  @param  String                           Pointer to a Null-terminated Unicode string.\r
+  @param  String                Pointer to a Null-terminated Unicode string.\r
 \r
   @retval UINT64\r
 \r
@@ -893,14 +885,16 @@ StrHexToUintn (
 UINT64\r
 EFIAPI\r
 StrHexToUint64 (\r
-  IN      CONST CHAR16               *String\r
+  IN      CONST CHAR16                *String\r
   )\r
 {\r
   UINT64    Result;\r
 \r
-  ASSERT (String != NULL);\r
-  ASSERT (((UINTN) String & 0x01) == 0);\r
-  ASSERT (StrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength));\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
@@ -1031,13 +1025,19 @@ InternalAsciiIsHexaDecimalDigitCharacter (
 CHAR8 *\r
 EFIAPI\r
 UnicodeStrToAsciiStr (\r
-  IN      CONST CHAR16               *Source,\r
-  OUT    CHAR8                           *Destination\r
+  IN      CONST CHAR16                *Source,\r
+  OUT     CHAR8                       *Destination\r
   )\r
 {\r
+  CHAR8                               *ReturnValue;\r
+\r
   ASSERT (Destination != NULL);\r
-  ASSERT (Source != NULL);\r
-  ASSERT (((UINTN) Source & 0x01) == 0);\r
+\r
+  //\r
+  // ASSERT if Source is long than PcdMaximumUnicodeStringLength.\r
+  // Length tests are performed inside StrLen().\r
+  //\r
+  ASSERT (StrSize (Source) != 0);\r
 \r
   //\r
   // Source and Destination should not overlap\r
@@ -1045,14 +1045,8 @@ UnicodeStrToAsciiStr (
   ASSERT ((UINTN) ((CHAR16 *) Destination -  Source) > StrLen (Source));\r
   ASSERT ((UINTN) ((CHAR8 *) Source - Destination) > StrLen (Source));\r
 \r
-  //\r
-  // If PcdMaximumUnicodeStringLength is not zero,\r
-  // length of Source should not more than PcdMaximumUnicodeStringLength\r
-  //\r
-  if (PcdGet32 (PcdMaximumUnicodeStringLength) != 0) {\r
-    ASSERT (StrLen (Source) < PcdGet32 (PcdMaximumUnicodeStringLength));\r
-  }\r
 \r
+  ReturnValue = Destination;\r
   while (*Source != '\0') {\r
     //\r
     // If any Unicode characters in Source contain \r
@@ -1063,8 +1057,14 @@ UnicodeStrToAsciiStr (
   }\r
 \r
   *Destination = '\0';\r
-  \r
-  return Destination;\r
+\r
+  //\r
+  // ASSERT Original Destination is less long than PcdMaximumAsciiStringLength.\r
+  // Length tests are performed inside AsciiStrLen().\r
+  //\r
+  ASSERT (AsciiStrSize (ReturnValue) != 0);\r
+\r
+  return ReturnValue;\r
 }\r
 \r
 \r
@@ -1563,8 +1563,8 @@ AsciiStrnCat (
   String contains more than PcdMaximumAsciiStringLength Unicode characters \r
   not including the Null-terminator, then ASSERT().\r
 \r
-  @param  String                                 Pointer to a Null-terminated ASCII string.\r
-  @param  SearchString   Pointer to a Null-terminated ASCII string to search for.\r
+  @param  String          Pointer to a Null-terminated ASCII string.\r
+  @param  SearchString    Pointer to a Null-terminated ASCII string to search for.\r
 \r
   @retval NULL            If the SearchString does not appear in String.\r
   @retval !NULL           If there is a match.\r
@@ -1573,31 +1573,18 @@ AsciiStrnCat (
 CHAR8 *\r
 EFIAPI\r
 AsciiStrStr (\r
-  IN      CONST CHAR8                *String,\r
+  IN      CONST CHAR8             *String,\r
   IN      CONST CHAR8             *SearchString\r
   )\r
 {\r
   CONST CHAR8 *FirstMatch;\r
   CONST CHAR8 *SearchStringTmp;\r
 \r
-  ASSERT (String != NULL);\r
-  ASSERT (SearchString != NULL);\r
-\r
   //\r
-  // If PcdMaximumUnicodeStringLength is not zero,\r
-  // length of String should not more than PcdMaximumUnicodeStringLength\r
+  // ASSERT both strings are less long than PcdMaximumAsciiStringLength\r
   //\r
-  if (PcdGet32 (PcdMaximumAsciiStringLength) != 0) {\r
-    ASSERT (AsciiStrLen (String) < PcdGet32 (PcdMaximumAsciiStringLength));\r
-  }\r
-\r
-  //\r
-  // If PcdMaximumUnicodeStringLength is not zero,\r
-  // length of SearchString should not more than PcdMaximumUnicodeStringLength\r
-  //\r
-  if (PcdGet32 (PcdMaximumAsciiStringLength) != 0) {\r
-    ASSERT (AsciiStrLen (SearchString) < PcdGet32 (PcdMaximumAsciiStringLength));\r
-  }\r
+  ASSERT (AsciiStrSize (String) != 0);\r
+  ASSERT (AsciiStrSize (SearchString) != 0);\r
 \r
   while (*String != '\0') {\r
     SearchStringTmp = SearchString;\r
@@ -1653,7 +1640,7 @@ AsciiStrStr (
   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, \r
   then ASSERT().\r
 \r
-  @param  String                           Pointer to a Null-terminated ASCII string.\r
+  @param  String                Pointer to a Null-terminated ASCII string.\r
 \r
   @retval UINTN           \r
 \r
@@ -1661,13 +1648,15 @@ AsciiStrStr (
 UINTN\r
 EFIAPI\r
 AsciiStrDecimalToUintn (\r
-  IN      CONST CHAR8                  *String\r
+  IN      CONST CHAR8               *String\r
   )\r
 {\r
   UINTN     Result;\r
   \r
-  ASSERT (String != NULL);\r
-  ASSERT (AsciiStrLen (String) < PcdGet32 (PcdMaximumAsciiStringLength));\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
@@ -1728,7 +1717,7 @@ AsciiStrDecimalToUintn (
   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, \r
   then ASSERT().\r
 \r
-  @param  String                           Pointer to a Null-terminated ASCII string.\r
+  @param  String                Pointer to a Null-terminated ASCII string.\r
 \r
   @retval UINT64           \r
 \r
@@ -1736,13 +1725,15 @@ AsciiStrDecimalToUintn (
 UINT64\r
 EFIAPI\r
 AsciiStrDecimalToUint64 (\r
-  IN      CONST CHAR8                *String\r
+  IN      CONST CHAR8             *String\r
   )\r
 {\r
   UINT64     Result;\r
   \r
-  ASSERT (String != NULL);\r
-  ASSERT (AsciiStrLen (String) < PcdGet32 (PcdMaximumAsciiStringLength));\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
@@ -1806,7 +1797,7 @@ AsciiStrDecimalToUint64 (
   and String contains more than PcdMaximumAsciiStringLength ASCII characters not including \r
   the Null-terminator, then ASSERT().\r
 \r
-  @param  String                           Pointer to a Null-terminated ASCII string.\r
+  @param  String                Pointer to a Null-terminated ASCII string.\r
 \r
   @retval UINTN\r
 \r
@@ -1814,13 +1805,15 @@ AsciiStrDecimalToUint64 (
 UINTN\r
 EFIAPI\r
 AsciiStrHexToUintn (\r
-  IN      CONST CHAR8                *String\r
+  IN      CONST CHAR8             *String\r
   )\r
 {\r
   UINTN     Result;\r
 \r
-  ASSERT (String != NULL);\r
-  ASSERT (AsciiStrLen (String) < PcdGet32 (PcdMaximumAsciiStringLength));\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
@@ -1896,7 +1889,7 @@ AsciiStrHexToUintn (
   and String contains more than PcdMaximumAsciiStringLength ASCII characters not including \r
   the Null-terminator, then ASSERT().\r
 \r
-  @param  String                           Pointer to a Null-terminated ASCII string.\r
+  @param  String                Pointer to a Null-terminated ASCII string.\r
 \r
   @retval UINT64\r
 \r
@@ -1904,13 +1897,15 @@ AsciiStrHexToUintn (
 UINT64\r
 EFIAPI\r
 AsciiStrHexToUint64 (\r
-  IN      CONST CHAR8                *String\r
+  IN      CONST CHAR8             *String\r
   )\r
 {\r
   UINT64    Result;\r
 \r
-  ASSERT (String != NULL);\r
-  ASSERT (AsciiStrLen (String) < PcdGet32 (PcdMaximumUnicodeStringLength));\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
@@ -1991,27 +1986,27 @@ AsciiStrHexToUint64 (
 CHAR16 *\r
 EFIAPI\r
 AsciiStrToUnicodeStr (\r
-  IN      CONST CHAR8                *Source,\r
-  OUT    CHAR16                        *Destination\r
+  IN      CONST CHAR8               *Source,\r
+  OUT     CHAR16                    *Destination\r
   )\r
 {\r
+  CHAR16                            *ReturnValue;\r
+\r
   ASSERT (Destination != NULL);\r
-  ASSERT (Source != NULL);\r
 \r
   //\r
-  // Source and Destination should not overlap\r
+  // ASSERT Source is less long than PcdMaximumAsciiStringLength\r
   //\r
-  ASSERT ((UINTN) ((CHAR8 *) Destination - Source) > AsciiStrLen (Source));\r
-  ASSERT ((UINTN) (Source - (CHAR8 *) Destination) > (AsciiStrLen (Source) * sizeof (CHAR16)));\r
+  ASSERT (AsciiStrSize (Source) != 0);\r
 \r
   //\r
-  // If PcdMaximumAsciiStringLength is not zero,\r
-  // length of Source should not more than PcdMaximumUnicodeStringLength\r
+  // Source and Destination should not overlap\r
   //\r
-  if (PcdGet32 (PcdMaximumAsciiStringLength) != 0) {\r
-    ASSERT (AsciiStrLen (Source) < PcdGet32 (PcdMaximumAsciiStringLength));\r
-  }\r
+  ASSERT ((UINTN) ((CHAR8 *) Destination - Source) > AsciiStrLen (Source));\r
+  ASSERT ((UINTN) (Source - (CHAR8 *) Destination) > (AsciiStrLen (Source) * sizeof (CHAR16)));\r
 \r
\r
+  ReturnValue = Destination;\r
   while (*Source != '\0') {\r
     *(Destination++) = (CHAR16) *(Source++);\r
   }\r
@@ -2020,7 +2015,12 @@ AsciiStrToUnicodeStr (
   //\r
   *Destination = '\0';\r
 \r
-  return Destination;\r
+  //\r
+  // ASSERT Original Destination is less long than PcdMaximumUnicodeStringLength\r
+  //\r
+  ASSERT (StrSize (ReturnValue) != 0);\r
+\r
+  return ReturnValue;\r
 }\r
 \r
 /**\r