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

Function StrnCpyS

MdePkg/Library/BaseLib/SafeString.c:312–374  ·  view source on GitHub ↗

Copies not more than Length successive char from the string pointed to by Source to the array pointed to by Destination. If no null char is copied from Source, then Destination[Length] is always set to null. This function is similar as strncpy_s defined in C11. If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT(). If Length > 0 and Source is not align

Source from the content-addressed store, hash-verified

310 @retval RETURN_ACCESS_DENIED If Source and Destination overlap.
311**/
312RETURN_STATUS
313EFIAPI
314StrnCpyS (
315 OUT CHAR16 *Destination,
316 IN UINTN DestMax,
317 IN CONST CHAR16 *Source,
318 IN UINTN Length
319 )
320{
321 UINTN SourceLen;
322
323 ASSERT (((UINTN) Destination & BIT0) == 0);
324 ASSERT (((UINTN) Source & BIT0) == 0);
325
326 //
327 // 1. Neither Destination nor Source shall be a null pointer.
328 //
329 SAFE_STRING_CONSTRAINT_CHECK ((Destination != NULL), RETURN_INVALID_PARAMETER);
330 SAFE_STRING_CONSTRAINT_CHECK ((Source != NULL), RETURN_INVALID_PARAMETER);
331
332 //
333 // 2. Neither DestMax nor Length shall be greater than RSIZE_MAX
334 //
335// if (RSIZE_MAX != 0) {
336// SAFE_STRING_CONSTRAINT_CHECK ((DestMax <= RSIZE_MAX), RETURN_INVALID_PARAMETER);
337// SAFE_STRING_CONSTRAINT_CHECK ((Length <= RSIZE_MAX), RETURN_INVALID_PARAMETER);
338// }
339
340 //
341 // 3. DestMax shall not equal zero.
342 //
343 SAFE_STRING_CONSTRAINT_CHECK ((DestMax != 0), RETURN_INVALID_PARAMETER);
344
345 //
346 // 4. If Length is not less than DestMax, then DestMax shall be greater than StrnLenS(Source, DestMax).
347 //
348 SourceLen = StrnLenS (Source, MIN (DestMax, Length)); //Slice: SourceLen <= DestMax
349// if (Length >= DestMax) {
350// SAFE_STRING_CONSTRAINT_CHECK ((DestMax > SourceLen), RETURN_BUFFER_TOO_SMALL);
351// }
352
353 //
354 // 5. Copying shall not take place between objects that overlap.
355 //
356 if (SourceLen > Length) {
357 SourceLen = Length;
358 }
359// SAFE_STRING_CONSTRAINT_CHECK (InternalSafeStringNoStrOverlap (Destination, DestMax, (CHAR16 *)Source, SourceLen + 1), RETURN_ACCESS_DENIED);
360
361 //
362 // The StrnCpyS function copies not more than Length successive characters (characters that
363 // follow a null character are not copied) from the array pointed to by Source to the array
364 // pointed to by Destination. If no null character was copied from Source, then Destination[Length] is set to a null
365 // character.
366 //
367 while ((SourceLen > 0) && (*Source != 0) && (--DestMax > 0)) {
368 *(Destination++) = *(Source++);
369 SourceLen--;

Callers 15

CreatePopUpFunction · 0.85
egSaveFileFunction · 0.85
FatHashLongNameFunction · 0.85
WrapGetNextVariableNameFunction · 0.85
GetNextParameterFunction · 0.85
UpdateStdInStdOutStdErrFunction · 0.85
CreateTabCompletionListFunction · 0.85
SetEnvironmentVariablesFunction · 0.85
GetExecuatableFileNameFunction · 0.85
GetManFileNameFunction · 0.85
DoHelpUpdateFunction · 0.85
RunScriptFileHandleFunction · 0.85

Calls 1

StrnLenSFunction · 0.70

Tested by

no test coverage detected