From 6b9dae0bef0fab82230a6672eaadd38d739e3e1e Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Sat, 27 Apr 2024 13:14:28 +0100 Subject: [PATCH] Fixup string functions for new CopyMem Signed-off-by: Callum Farmer --- lib/runtime/rtstr.c | 14 +++++++++++--- lib/str.c | 4 +++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/runtime/rtstr.c b/lib/runtime/rtstr.c index 802e7f4..902e075 100644 --- a/lib/runtime/rtstr.c +++ b/lib/runtime/rtstr.c @@ -69,10 +69,13 @@ RtStrnCpy ( ) // copy strings { + CHAR16 CopySrc = *Src; + CHAR16 *PCopySrc = &CopySrc; + UINTN Size = RtStrnLen(Src, Len); if (Size != Len) RtSetMem(Dest + Size, (Len - Size) * sizeof(CHAR16), '\0'); - RtCopyMem(Dest, Src, Size * sizeof(CHAR16)); + RtCopyMem(Dest, PCopySrc, Size * sizeof(CHAR16)); } #ifndef __GNUC__ @@ -105,10 +108,13 @@ RtStpnCpy ( ) // copy strings { + CHAR16 CopySrc = *Src; + CHAR16 *PCopySrc = &CopySrc; + UINTN Size = RtStrnLen(Src, Len); if (Size != Len) RtSetMem(Dest + Size, (Len - Size) * sizeof(CHAR16), '\0'); - RtCopyMem(Dest, Src, Size * sizeof(CHAR16)); + RtCopyMem(Dest, PCopySrc, Size * sizeof(CHAR16)); return Dest + Size; } @@ -137,10 +143,12 @@ RtStrnCat ( ) { UINTN DestSize, Size; + CHAR16 CopySrc = *Src; + CHAR16 *PCopySrc = &CopySrc; DestSize = RtStrLen(Dest); Size = RtStrnLen(Src, Len); - RtCopyMem(Dest + DestSize, Src, Size * sizeof(CHAR16)); + RtCopyMem(Dest + DestSize, PCopySrc, Size * sizeof(CHAR16)); Dest[DestSize + Size] = '\0'; } diff --git a/lib/str.c b/lib/str.c index a2f8750..0752e06 100644 --- a/lib/str.c +++ b/lib/str.c @@ -201,11 +201,13 @@ StrDuplicate ( { CHAR16 *Dest; UINTN Size; + CHAR16 CopySrc = *Src; + CHAR16 *PCopySrc = &CopySrc; Size = StrSize(Src); Dest = AllocatePool (Size); if (Dest) { - CopyMem (Dest, (void *)Src, Size); + CopyMem (Dest, PCopySrc, Size); } return Dest; }