/** @file\r
Safe String functions.\r
\r
- Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>\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
@retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
If Source is NULL.\r
If PcdMaximumUnicodeStringLength is not zero,\r
- and DestMax is greater than \r
+ and DestMax is greater than\r
PcdMaximumUnicodeStringLength.\r
If DestMax is 0.\r
@retval RETURN_ACCESS_DENIED If Source and Destination overlap.\r
)\r
{\r
UINTN SourceLen;\r
- \r
+\r
ASSERT (((UINTN) Destination & BIT0) == 0);\r
ASSERT (((UINTN) Source & BIT0) == 0);\r
\r
@param Length The maximum number of Unicode characters to copy.\r
\r
@retval RETURN_SUCCESS String is copied.\r
- @retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than \r
+ @retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than\r
MIN(StrLen(Source), Length).\r
@retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
If Source is NULL.\r
If PcdMaximumUnicodeStringLength is not zero,\r
- and DestMax is greater than \r
+ and DestMax is greater than\r
PcdMaximumUnicodeStringLength.\r
If DestMax is 0.\r
@retval RETURN_ACCESS_DENIED If Source and Destination overlap.\r
//\r
// 4. If Length is not less than DestMax, then DestMax shall be greater than StrnLenS(Source, DestMax).\r
//\r
- SourceLen = StrnLenS (Source, DestMax);\r
+ SourceLen = StrnLenS (Source, MIN (DestMax, Length));\r
if (Length >= DestMax) {\r
SAFE_STRING_CONSTRAINT_CHECK ((DestMax > SourceLen), RETURN_BUFFER_TOO_SMALL);\r
}\r
// pointed to by Destination. If no null character was copied from Source, then Destination[Length] is set to a null\r
// character.\r
//\r
- while ((*Source != 0) && (SourceLen > 0)) {\r
+ while ((SourceLen > 0) && (*Source != 0)) {\r
*(Destination++) = *(Source++);\r
SourceLen--;\r
}\r
@param Source A pointer to a Null-terminated Unicode string.\r
\r
@retval RETURN_SUCCESS String is appended.\r
- @retval RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than \r
+ @retval RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than\r
StrLen(Destination).\r
@retval RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT\r
greater than StrLen(Source).\r
@retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
If Source is NULL.\r
If PcdMaximumUnicodeStringLength is not zero,\r
- and DestMax is greater than \r
+ and DestMax is greater than\r
PcdMaximumUnicodeStringLength.\r
If DestMax is 0.\r
@retval RETURN_ACCESS_DENIED If Source and Destination overlap.\r
UINTN DestLen;\r
UINTN CopyLen;\r
UINTN SourceLen;\r
- \r
+\r
ASSERT (((UINTN) Destination & BIT0) == 0);\r
ASSERT (((UINTN) Source & BIT0) == 0);\r
\r
@retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
If Source is NULL.\r
If PcdMaximumUnicodeStringLength is not zero,\r
- and DestMax is greater than \r
+ and DestMax is greater than\r
PcdMaximumUnicodeStringLength.\r
If DestMax is 0.\r
@retval RETURN_ACCESS_DENIED If Source and Destination overlap.\r
UINTN DestLen;\r
UINTN CopyLen;\r
UINTN SourceLen;\r
- \r
+\r
ASSERT (((UINTN) Destination & BIT0) == 0);\r
ASSERT (((UINTN) Source & BIT0) == 0);\r
\r
//\r
// 5. If Length is not less than CopyLen, then CopyLen shall be greater than StrnLenS(Source, CopyLen).\r
//\r
- SourceLen = StrnLenS (Source, CopyLen);\r
+ SourceLen = StrnLenS (Source, MIN (CopyLen, Length));\r
if (Length >= CopyLen) {\r
SAFE_STRING_CONSTRAINT_CHECK ((CopyLen > SourceLen), RETURN_BUFFER_TOO_SMALL);\r
}\r
// a null character.\r
//\r
Destination = Destination + DestLen;\r
- while ((*Source != 0) && (SourceLen > 0)) {\r
+ while ((SourceLen > 0) && (*Source != 0)) {\r
*(Destination++) = *(Source++);\r
SourceLen--;\r
}\r
@retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
If Source is NULL.\r
If PcdMaximumAsciiStringLength is not zero,\r
- and DestMax is greater than \r
+ and DestMax is greater than\r
PcdMaximumAsciiStringLength.\r
If DestMax is 0.\r
@retval RETURN_ACCESS_DENIED If Source and Destination overlap.\r
)\r
{\r
UINTN SourceLen;\r
- \r
+\r
//\r
// 1. Neither Destination nor Source shall be a null pointer.\r
//\r
@param Length The maximum number of Ascii characters to copy.\r
\r
@retval RETURN_SUCCESS String is copied.\r
- @retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than \r
+ @retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than\r
MIN(StrLen(Source), Length).\r
@retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
If Source is NULL.\r
If PcdMaximumAsciiStringLength is not zero,\r
- and DestMax is greater than \r
+ and DestMax is greater than\r
PcdMaximumAsciiStringLength.\r
If DestMax is 0.\r
@retval RETURN_ACCESS_DENIED If Source and Destination overlap.\r
//\r
// 4. If Length is not less than DestMax, then DestMax shall be greater than AsciiStrnLenS(Source, DestMax).\r
//\r
- SourceLen = AsciiStrnLenS (Source, DestMax);\r
+ SourceLen = AsciiStrnLenS (Source, MIN (DestMax, Length));\r
if (Length >= DestMax) {\r
SAFE_STRING_CONSTRAINT_CHECK ((DestMax > SourceLen), RETURN_BUFFER_TOO_SMALL);\r
}\r
// pointed to by Destination. If no null character was copied from Source, then Destination[Length] is set to a null\r
// character.\r
//\r
- while ((*Source != 0) && (SourceLen > 0)) {\r
+ while ((SourceLen > 0) && (*Source != 0)) {\r
*(Destination++) = *(Source++);\r
SourceLen--;\r
}\r
@param Source A pointer to a Null-terminated Ascii string.\r
\r
@retval RETURN_SUCCESS String is appended.\r
- @retval RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than \r
+ @retval RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than\r
StrLen(Destination).\r
@retval RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT\r
greater than StrLen(Source).\r
@retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
If Source is NULL.\r
If PcdMaximumAsciiStringLength is not zero,\r
- and DestMax is greater than \r
+ and DestMax is greater than\r
PcdMaximumAsciiStringLength.\r
If DestMax is 0.\r
@retval RETURN_ACCESS_DENIED If Source and Destination overlap.\r
UINTN DestLen;\r
UINTN CopyLen;\r
UINTN SourceLen;\r
- \r
+\r
//\r
// Let CopyLen denote the value DestMax - AsciiStrnLenS(Destination, DestMax) upon entry to AsciiStrCatS.\r
//\r
@retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
If Source is NULL.\r
If PcdMaximumAsciiStringLength is not zero,\r
- and DestMax is greater than \r
+ and DestMax is greater than\r
PcdMaximumAsciiStringLength.\r
If DestMax is 0.\r
@retval RETURN_ACCESS_DENIED If Source and Destination overlap.\r
UINTN DestLen;\r
UINTN CopyLen;\r
UINTN SourceLen;\r
- \r
+\r
//\r
// Let CopyLen denote the value DestMax - AsciiStrnLenS(Destination, DestMax) upon entry to AsciiStrnCatS.\r
//\r
//\r
// 5. If Length is not less than CopyLen, then CopyLen shall be greater than AsciiStrnLenS(Source, CopyLen).\r
//\r
- SourceLen = AsciiStrnLenS (Source, CopyLen);\r
+ SourceLen = AsciiStrnLenS (Source, MIN (CopyLen, Length));\r
if (Length >= CopyLen) {\r
SAFE_STRING_CONSTRAINT_CHECK ((CopyLen > SourceLen), RETURN_BUFFER_TOO_SMALL);\r
}\r
// a null character.\r
//\r
Destination = Destination + DestLen;\r
- while ((*Source != 0) && (SourceLen > 0)) {\r
+ while ((SourceLen > 0) && (*Source != 0)) {\r
*(Destination++) = *(Source++);\r
SourceLen--;\r
}\r
// Convert string\r
//\r
while (*Source != '\0') {\r
- *(Destination++) = (CHAR16)*(Source++);\r
+ *(Destination++) = (CHAR16)(UINT8)*(Source++);\r
}\r
*Destination = '\0';\r
\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
&Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressIndex],\r
&LocalAddress.Addr[CompressStart],\r
AddressIndex - CompressStart\r
- );\r\r
+ );\r
+\r
}\r
\r
if (PrefixLength != NULL) {\r