Skip to content

Commit

Permalink
Fixup string functions for new CopyMem
Browse files Browse the repository at this point in the history
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
  • Loading branch information
gmbr3 committed Apr 27, 2024
1 parent f5bb548 commit 6b9dae0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 11 additions & 3 deletions lib/runtime/rtstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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';
}

Expand Down
4 changes: 3 additions & 1 deletion lib/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 6b9dae0

Please sign in to comment.