瀏覽代碼

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>
Gary Lin 6 年之前
父節點
當前提交
ba250504b9
共有 1 個文件被更改,包括 7 次插入2 次删除
  1. 7 2
      lib/runtime/rtstr.c

+ 7 - 2
lib/runtime/rtstr.c

@@ -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__