Implement StrnCat() without StrnCpy()

StrnCpy() doesn't guarantee the dest string will be null-terminated, so
we shouldn't use StrnCpy().

Signed-off-by: Gary Lin <glin@suse.com>
Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
This commit is contained in:
Gary Lin 2018-10-11 12:02:27 +08:00 committed by Nigel Croxon
parent 6058ffcd54
commit ba250504b9

View File

@ -126,7 +126,7 @@ RtStrCat (
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrCat)
#pragma RUNTIME_CODE(RtStrnCat)
#endif
VOID
RUNTIMEFUNCTION
@ -136,7 +136,12 @@ RtStrnCat (
IN UINTN Len
)
{
RtStrnCpy(Dest+StrLen(Dest), Src, Len);
UINTN DestSize, Size;
DestSize = StrLen(Dest);
Size = RtStrnLen(Src, Len);
RtCopyMem(Dest + DestSize, Src, Size * sizeof(CHAR16));
Dest[DestSize + Size] = '\0';
}
#ifndef __GNUC__