MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / AsciiStrnCatS

Function AsciiStrnCatS

MdePkg/Library/BaseLib/SafeString.c:2082–2156  ·  view source on GitHub ↗

Appends not more than Length successive char from the string pointed to by Source to the end of the string pointed to by Destination. If no null char is copied from Source, then Destination[StrLen(Destination) + Length] is always set to null. This function is similar as strncat_s defined in C11. If an error would be returned, then the function will also ASSERT(). If an erro

Source from the content-addressed store, hash-verified

2080 @retval RETURN_ACCESS_DENIED If Source and Destination overlap.
2081**/
2082RETURN_STATUS
2083EFIAPI
2084AsciiStrnCatS (
2085 IN OUT CHAR8 *Destination,
2086 IN UINTN DestMax,
2087 IN CONST CHAR8 *Source,
2088 IN UINTN Length
2089 )
2090{
2091 UINTN DestLen;
2092 UINTN CopyLen;
2093 UINTN SourceLen;
2094
2095 //
2096 // Let CopyLen denote the value DestMax - AsciiStrnLenS(Destination, DestMax) upon entry to AsciiStrnCatS.
2097 //
2098 DestLen = AsciiStrnLenS (Destination, DestMax);
2099 CopyLen = DestMax - DestLen;
2100
2101 //
2102 // 1. Neither Destination nor Source shall be a null pointer.
2103 //
2104 SAFE_STRING_CONSTRAINT_CHECK ((Destination != NULL), RETURN_INVALID_PARAMETER);
2105 SAFE_STRING_CONSTRAINT_CHECK ((Source != NULL), RETURN_INVALID_PARAMETER);
2106
2107 //
2108 // 2. Neither DestMax nor Length shall be greater than ASCII_RSIZE_MAX.
2109 //
2110// if (ASCII_RSIZE_MAX != 0) {
2111// SAFE_STRING_CONSTRAINT_CHECK ((DestMax <= ASCII_RSIZE_MAX), RETURN_INVALID_PARAMETER);
2112// SAFE_STRING_CONSTRAINT_CHECK ((Length <= ASCII_RSIZE_MAX), RETURN_INVALID_PARAMETER);
2113// }
2114
2115 //
2116 // 3. DestMax shall not equal zero.
2117 //
2118 SAFE_STRING_CONSTRAINT_CHECK ((DestMax != 0), RETURN_INVALID_PARAMETER);
2119
2120 //
2121 // 4. CopyLen shall not equal zero.
2122 //
2123 SAFE_STRING_CONSTRAINT_CHECK ((CopyLen != 0), RETURN_BAD_BUFFER_SIZE);
2124
2125 //
2126 // 5. If Length is not less than CopyLen, then CopyLen shall be greater than AsciiStrnLenS(Source, CopyLen).
2127 //
2128 SourceLen = AsciiStrnLenS (Source, MIN (CopyLen, Length));
2129// if (Length >= CopyLen) {
2130// SAFE_STRING_CONSTRAINT_CHECK ((CopyLen > SourceLen), RETURN_BUFFER_TOO_SMALL);
2131// }
2132
2133 //
2134 // 6. Copying shall not take place between objects that overlap.
2135 //
2136 if (SourceLen > Length) {
2137 SourceLen = Length;
2138 }
2139// SAFE_STRING_CONSTRAINT_CHECK (InternalSafeStringNoAsciiStrOverlap (Destination, DestMax, (CHAR8 *)Source, SourceLen + 1), RETURN_ACCESS_DENIED);

Callers 1

GetPlistHexValueFunction · 0.85

Calls 1

AsciiStrnLenSFunction · 0.85

Tested by

no test coverage detected