]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/SafeString.c
MdePkg: Reproduce builds across source format changes
[mirror_edk2.git] / MdePkg / Library / BaseLib / SafeString.c
index 29310889cabbfee7f108196ffd0c3c85a6f18ee2..24e818b921ea14e51671bc417e36286612d62d32 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   Safe String functions.\r
 \r
-  Copyright (c) 2014 - 2018, 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
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 \r
 #define SAFE_STRING_CONSTRAINT_CHECK(Expression, Status)  \\r
   do { \\r
-    ASSERT (Expression); \\r
     if (!(Expression)) { \\r
+      DEBUG ((DEBUG_VERBOSE, \\r
+        "%a(%d) %a: SAFE_STRING_CONSTRAINT_CHECK(%a) failed.  Return %r\n", \\r
+        __FILE__, DEBUG_LINE_NUMBER, __FUNCTION__, DEBUG_EXPRESSION_STRING (Expression), Status)); \\r
       return Status; \\r
     } \\r
   } while (FALSE)\r
@@ -203,7 +199,6 @@ StrnSizeS (
 \r
   If Destination is not aligned on a 16-bit boundary, then ASSERT().\r
   If Source is not aligned on a 16-bit boundary, then ASSERT().\r
-  If an error would be returned, then the function will also ASSERT().\r
 \r
   If an error is returned, then the Destination is unmodified.\r
 \r
@@ -285,7 +280,6 @@ StrCpyS (
 \r
   If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().\r
   If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().\r
-  If an error would be returned, then the function will also ASSERT().\r
 \r
   If an error is returned, then the Destination is unmodified.\r
 \r
@@ -378,7 +372,6 @@ StrnCpyS (
 \r
   If Destination is not aligned on a 16-bit boundary, then ASSERT().\r
   If Source is not aligned on a 16-bit boundary, then ASSERT().\r
-  If an error would be returned, then the function will also ASSERT().\r
 \r
   If an error is returned, then the Destination is unmodified.\r
 \r
@@ -479,7 +472,6 @@ StrCatS (
 \r
   If Destination is not aligned on a 16-bit boundary, then ASSERT().\r
   If Source is not aligned on a 16-bit boundary, then ASSERT().\r
-  If an error would be returned, then the function will also ASSERT().\r
 \r
   If an error is returned, then the Destination is unmodified.\r
 \r
@@ -596,12 +588,7 @@ StrnCatS (
   be ignored. Then, the function stops at the first character that is a not a\r
   valid decimal character or a Null-terminator, whichever one comes first.\r
 \r
-  If String is NULL, then ASSERT().\r
-  If Data is NULL, then ASSERT().\r
   If String is not aligned in a 16-bit boundary, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
-  PcdMaximumUnicodeStringLength Unicode characters, not including the\r
-  Null-terminator, then ASSERT().\r
 \r
   If String has no valid decimal digits in the above format, then 0 is stored\r
   at the location pointed to by Data.\r
@@ -711,12 +698,7 @@ StrDecimalToUintnS (
   be ignored. Then, the function stops at the first character that is a not a\r
   valid decimal character or a Null-terminator, whichever one comes first.\r
 \r
-  If String is NULL, then ASSERT().\r
-  If Data is NULL, then ASSERT().\r
   If String is not aligned in a 16-bit boundary, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
-  PcdMaximumUnicodeStringLength Unicode characters, not including the\r
-  Null-terminator, then ASSERT().\r
 \r
   If String has no valid decimal digits in the above format, then 0 is stored\r
   at the location pointed to by Data.\r
@@ -831,12 +813,7 @@ StrDecimalToUint64S (
   the first character that is a not a valid hexadecimal character or NULL,\r
   whichever one comes first.\r
 \r
-  If String is NULL, then ASSERT().\r
-  If Data is NULL, then ASSERT().\r
   If String is not aligned in a 16-bit boundary, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
-  PcdMaximumUnicodeStringLength Unicode characters, not including the\r
-  Null-terminator, then ASSERT().\r
 \r
   If String has no valid hexadecimal digits in the above format, then 0 is\r
   stored at the location pointed to by Data.\r
@@ -905,7 +882,7 @@ StrHexToUintnS (
     String++;\r
   }\r
 \r
-  if (InternalCharToUpper (*String) == L'X') {\r
+  if (CharToUpper (*String) == L'X') {\r
     if (*(String - 1) != L'0') {\r
       *Data = 0;\r
       return RETURN_SUCCESS;\r
@@ -962,12 +939,7 @@ StrHexToUintnS (
   the first character that is a not a valid hexadecimal character or NULL,\r
   whichever one comes first.\r
 \r
-  If String is NULL, then ASSERT().\r
-  If Data is NULL, then ASSERT().\r
   If String is not aligned in a 16-bit boundary, then ASSERT().\r
-  If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
-  PcdMaximumUnicodeStringLength Unicode characters, not including the\r
-  Null-terminator, then ASSERT().\r
 \r
   If String has no valid hexadecimal digits in the above format, then 0 is\r
   stored at the location pointed to by Data.\r
@@ -1036,7 +1008,7 @@ StrHexToUint64S (
     String++;\r
   }\r
 \r
-  if (InternalCharToUpper (*String) == L'X') {\r
+  if (CharToUpper (*String) == L'X') {\r
     if (*(String - 1) != L'0') {\r
       *Data = 0;\r
       return RETURN_SUCCESS;\r
@@ -1097,16 +1069,8 @@ StrHexToUint64S (
   "::" can be used to compress one or more groups of X when X contains only 0.\r
   The "::" can only appear once in the String.\r
 \r
-  If String is NULL, then ASSERT().\r
-\r
-  If Address is NULL, then ASSERT().\r
-\r
   If String is not aligned in a 16-bit boundary, then ASSERT().\r
 \r
-  If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
-  PcdMaximumUnicodeStringLength Unicode characters, not including the\r
-  Null-terminator, then ASSERT().\r
-\r
   If EndPointer is not NULL and Address is translated from String, a pointer\r
   to the character that stopped the scan is stored at the location pointed to\r
   by EndPointer.\r
@@ -1323,16 +1287,8 @@ StrToIpv6Address (
   When /P is in the String, the function stops at the first character that is not\r
   a valid decimal digit character after P is converted.\r
 \r
-  If String is NULL, then ASSERT().\r
-\r
-  If Address is NULL, then ASSERT().\r
-\r
   If String is not aligned in a 16-bit boundary, then ASSERT().\r
 \r
-  If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
-  PcdMaximumUnicodeStringLength Unicode characters, not including the\r
-  Null-terminator, then ASSERT().\r
-\r
   If EndPointer is not NULL and Address is translated from String, a pointer\r
   to the character that stopped the scan is stored at the location pointed to\r
   by EndPointer.\r
@@ -1488,8 +1444,6 @@ StrToIpv4Address (
                   oo          Data4[48:55]\r
                   pp          Data4[56:63]\r
 \r
-  If String is NULL, then ASSERT().\r
-  If Guid is NULL, then ASSERT().\r
   If String is not aligned in a 16-bit boundary, then ASSERT().\r
 \r
   @param  String                   Pointer to a Null-terminated Unicode string.\r
@@ -1595,17 +1549,6 @@ StrToGuid (
 \r
   If String is not aligned in a 16-bit boundary, then ASSERT().\r
 \r
-  If String is NULL, then ASSERT().\r
-\r
-  If Buffer is NULL, then ASSERT().\r
-\r
-  If Length is not multiple of 2, then ASSERT().\r
-\r
-  If PcdMaximumUnicodeStringLength is not zero and Length is greater than\r
-  PcdMaximumUnicodeStringLength, then ASSERT().\r
-\r
-  If MaxBufferSize is less than (Length / 2), then ASSERT().\r
-\r
   @param  String                   Pointer to a Null-terminated Unicode string.\r
   @param  Length                   The number of Unicode characters to decode.\r
   @param  Buffer                   Pointer to the converted bytes array.\r
@@ -1785,8 +1728,6 @@ AsciiStrnSizeS (
 \r
   This function is similar as strcpy_s defined in C11.\r
 \r
-  If an error would be returned, then the function will also ASSERT().\r
-\r
   If an error is returned, then the Destination is unmodified.\r
 \r
   @param  Destination              A pointer to a Null-terminated Ascii string.\r
@@ -1862,8 +1803,6 @@ AsciiStrCpyS (
 \r
   This function is similar as strncpy_s defined in C11.\r
 \r
-  If an error would be returned, then the function will also ASSERT().\r
-\r
   If an error is returned, then the Destination is unmodified.\r
 \r
   @param  Destination              A pointer to a Null-terminated Ascii string.\r
@@ -1950,8 +1889,6 @@ AsciiStrnCpyS (
 \r
   This function is similar as strcat_s defined in C11.\r
 \r
-  If an error would be returned, then the function will also ASSERT().\r
-\r
   If an error is returned, then the Destination is unmodified.\r
 \r
   @param  Destination              A pointer to a Null-terminated Ascii string.\r
@@ -2046,8 +1983,6 @@ AsciiStrCatS (
 \r
   This function is similar as strncat_s defined in C11.\r
 \r
-  If an error would be returned, then the function will also ASSERT().\r
-\r
   If an error is returned, then the Destination is unmodified.\r
 \r
   @param  Destination              A pointer to a Null-terminated Ascii string.\r
@@ -2160,12 +2095,6 @@ AsciiStrnCatS (
   be ignored. Then, the function stops at the first character that is a not a\r
   valid decimal character or a Null-terminator, whichever one comes first.\r
 \r
-  If String is NULL, then ASSERT().\r
-  If Data is NULL, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero, and String contains more than\r
-  PcdMaximumAsciiStringLength Ascii characters, not including the\r
-  Null-terminator, then ASSERT().\r
-\r
   If String has no valid decimal digits in the above format, then 0 is stored\r
   at the location pointed to by Data.\r
   If the number represented by String exceeds the range defined by UINTN, then\r
@@ -2272,12 +2201,6 @@ AsciiStrDecimalToUintnS (
   be ignored. Then, the function stops at the first character that is a not a\r
   valid decimal character or a Null-terminator, whichever one comes first.\r
 \r
-  If String is NULL, then ASSERT().\r
-  If Data is NULL, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero, and String contains more than\r
-  PcdMaximumAsciiStringLength Ascii characters, not including the\r
-  Null-terminator, then ASSERT().\r
-\r
   If String has no valid decimal digits in the above format, then 0 is stored\r
   at the location pointed to by Data.\r
   If the number represented by String exceeds the range defined by UINT64, then\r
@@ -2388,12 +2311,6 @@ AsciiStrDecimalToUint64S (
   character that is a not a valid hexadecimal character or Null-terminator,\r
   whichever on comes first.\r
 \r
-  If String is NULL, then ASSERT().\r
-  If Data is NULL, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero, and String contains more than\r
-  PcdMaximumAsciiStringLength Ascii characters, not including the\r
-  Null-terminator, then ASSERT().\r
-\r
   If String has no valid hexadecimal digits in the above format, then 0 is\r
   stored at the location pointed to by Data.\r
   If the number represented by String exceeds the range defined by UINTN, then\r
@@ -2459,7 +2376,7 @@ AsciiStrHexToUintnS (
     String++;\r
   }\r
 \r
-  if (InternalBaseLibAsciiToUpper (*String) == 'X') {\r
+  if (AsciiCharToUpper (*String) == 'X') {\r
     if (*(String - 1) != '0') {\r
       *Data = 0;\r
       return RETURN_SUCCESS;\r
@@ -2515,12 +2432,6 @@ AsciiStrHexToUintnS (
   character that is a not a valid hexadecimal character or Null-terminator,\r
   whichever on comes first.\r
 \r
-  If String is NULL, then ASSERT().\r
-  If Data is NULL, then ASSERT().\r
-  If PcdMaximumAsciiStringLength is not zero, and String contains more than\r
-  PcdMaximumAsciiStringLength Ascii characters, not including the\r
-  Null-terminator, then ASSERT().\r
-\r
   If String has no valid hexadecimal digits in the above format, then 0 is\r
   stored at the location pointed to by Data.\r
   If the number represented by String exceeds the range defined by UINT64, then\r
@@ -2586,7 +2497,7 @@ AsciiStrHexToUint64S (
     String++;\r
   }\r
 \r
-  if (InternalBaseLibAsciiToUpper (*String) == 'X') {\r
+  if (AsciiCharToUpper (*String) == 'X') {\r
     if (*(String - 1) != '0') {\r
       *Data = 0;\r
       return RETURN_SUCCESS;\r
@@ -2641,7 +2552,6 @@ AsciiStrHexToUint64S (
   the upper 8 bits, then ASSERT().\r
 \r
   If Source is not aligned on a 16-bit boundary, then ASSERT().\r
-  If an error would be returned, then the function will also ASSERT().\r
 \r
   If an error is returned, then the Destination is unmodified.\r
 \r
@@ -2741,7 +2651,6 @@ UnicodeStrToAsciiStrS (
   If any Unicode characters in Source contain non-zero value in the upper 8\r
   bits, then ASSERT().\r
   If Source is not aligned on a 16-bit boundary, then ASSERT().\r
-  If an error would be returned, then the function will also ASSERT().\r
 \r
   If an error is returned, then Destination and DestinationLength are\r
   unmodified.\r
@@ -2861,7 +2770,6 @@ UnicodeStrnToAsciiStrS (
   equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.\r
 \r
   If Destination is not aligned on a 16-bit boundary, then ASSERT().\r
-  If an error would be returned, then the function will also ASSERT().\r
 \r
   If an error is returned, then the Destination is unmodified.\r
 \r
@@ -2932,7 +2840,7 @@ AsciiStrToUnicodeStrS (
   // Convert string\r
   //\r
   while (*Source != '\0') {\r
-    *(Destination++) = (CHAR16)*(Source++);\r
+    *(Destination++) = (CHAR16)(UINT8)*(Source++);\r
   }\r
   *Destination = '\0';\r
 \r
@@ -2954,7 +2862,6 @@ AsciiStrToUnicodeStrS (
   ((MIN(AsciiStrLen(Source), Length) + 1) * sizeof (CHAR8)) in bytes.\r
 \r
   If Destination is not aligned on a 16-bit boundary, then ASSERT().\r
-  If an error would be returned, then the function will also ASSERT().\r
 \r
   If an error is returned, then Destination and DestinationLength are\r
   unmodified.\r
@@ -3045,7 +2952,7 @@ AsciiStrnToUnicodeStrS (
   // Convert string\r
   //\r
   while ((*Source != 0) && (SourceLen > 0)) {\r
-    *(Destination++) = (CHAR16)*(Source++);\r
+    *(Destination++) = (CHAR16)(UINT8)*(Source++);\r
     SourceLen--;\r
     (*DestinationLength)++;\r
   }\r
@@ -3078,10 +2985,6 @@ AsciiStrnToUnicodeStrS (
   "::" can be used to compress one or more groups of X when X contains only 0.\r
   The "::" can only appear once in the String.\r
 \r
-  If String is NULL, then ASSERT().\r
-\r
-  If Address is NULL, then ASSERT().\r
-\r
   If EndPointer is not NULL and Address is translated from String, a pointer\r
   to the character that stopped the scan is stored at the location pointed to\r
   by EndPointer.\r
@@ -3297,10 +3200,6 @@ AsciiStrToIpv6Address (
   When /P is in the String, the function stops at the first character that is not\r
   a valid decimal digit character after P is converted.\r
 \r
-  If String is NULL, then ASSERT().\r
-\r
-  If Address is NULL, then ASSERT().\r
-\r
   If EndPointer is not NULL and Address is translated from String, a pointer\r
   to the character that stopped the scan is stored at the location pointed to\r
   by EndPointer.\r
@@ -3454,9 +3353,6 @@ AsciiStrToIpv4Address (
                   oo          Data4[48:55]\r
                   pp          Data4[56:63]\r
 \r
-  If String is NULL, then ASSERT().\r
-  If Guid is NULL, then ASSERT().\r
-\r
   @param  String                   Pointer to a Null-terminated ASCII string.\r
   @param  Guid                     Pointer to the converted GUID.\r
 \r
@@ -3556,17 +3452,6 @@ AsciiStrToGuid (
   decoding stops after Length of characters and outputs Buffer containing\r
   (Length / 2) bytes.\r
 \r
-  If String is NULL, then ASSERT().\r
-\r
-  If Buffer is NULL, then ASSERT().\r
-\r
-  If Length is not multiple of 2, then ASSERT().\r
-\r
-  If PcdMaximumAsciiStringLength is not zero and Length is greater than\r
-  PcdMaximumAsciiStringLength, then ASSERT().\r
-\r
-  If MaxBufferSize is less than (Length / 2), then ASSERT().\r
-\r
   @param  String                   Pointer to a Null-terminated ASCII string.\r
   @param  Length                   The number of ASCII characters to decode.\r
   @param  Buffer                   Pointer to the converted bytes array.\r