/** @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
\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
\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
\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
\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
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
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
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
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
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
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
"::" 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
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
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
\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
\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
\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
\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
\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
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
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
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
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
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
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
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
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
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
// Convert string\r
//\r
while (*Source != '\0') {\r
- *(Destination++) = (CHAR16)*(Source++);\r
+ *(Destination++) = (CHAR16)(UINT8)*(Source++);\r
}\r
*Destination = '\0';\r
\r
((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
// Convert string\r
//\r
while ((*Source != 0) && (SourceLen > 0)) {\r
- *(Destination++) = (CHAR16)*(Source++);\r
+ *(Destination++) = (CHAR16)(UINT8)*(Source++);\r
SourceLen--;\r
(*DestinationLength)++;\r
}\r
"::" 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
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
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
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