[libc-commits] [libc] Revert "Fix wcpncpy() return value; add test." (PR #146752)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Wed Jul 2 11:08:12 PDT 2025


https://github.com/michaelrj-google created https://github.com/llvm/llvm-project/pull/146752

This reverts commit 988876cdd918d5b945a072a3d643b5fa22ae2917.
Was intended to be a PR


>From fa0e4a747b89e4bb79fc6902ed6317aab9143340 Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Wed, 2 Jul 2025 11:06:36 -0700
Subject: [PATCH] Revert "Fix wcpncpy() return value; add test."

This reverts commit 988876cdd918d5b945a072a3d643b5fa22ae2917.
Was intended to be a PR
---
 libc/src/wchar/wcpncpy.cpp           | 5 ++---
 libc/test/src/wchar/wcpncpy_test.cpp | 9 ---------
 2 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/libc/src/wchar/wcpncpy.cpp b/libc/src/wchar/wcpncpy.cpp
index 0e729db7abf60..9f451b73f07cb 100644
--- a/libc/src/wchar/wcpncpy.cpp
+++ b/libc/src/wchar/wcpncpy.cpp
@@ -28,9 +28,8 @@ LLVM_LIBC_FUNCTION(wchar_t *, wcpncpy,
   for (i = 0; i < n && s2[i] != '\0'; ++i)
     s1[i] = s2[i];
   // When n>strlen(src), n-strlen(src) \0 are appended.
-  for (size_t j = i; j < n; ++j)
-    s1[j] = L'\0';
-  // ...but our result points to the first \0 (if any).
+  for (; i < n; ++i)
+    s1[i] = L'\0';
   return s1 + i;
 }
 
diff --git a/libc/test/src/wchar/wcpncpy_test.cpp b/libc/test/src/wchar/wcpncpy_test.cpp
index 5ce3e8ce7cd93..98738e230e32d 100644
--- a/libc/test/src/wchar/wcpncpy_test.cpp
+++ b/libc/test/src/wchar/wcpncpy_test.cpp
@@ -75,15 +75,6 @@ TEST(LlvmLibcWCPNCpyTest, CopyTwoWithNull) {
   ASSERT_EQ(dest + 2, res);
 }
 
-TEST(LlvmLibcWCPNCpyTest, CopyAndFill) {
-  wchar_t dest[] = {L'a', L'b', L'c'};
-  wchar_t *res = LIBC_NAMESPACE::wcpncpy(dest, L"x", 3);
-  ASSERT_TRUE(dest[0] == L'x');
-  ASSERT_TRUE(dest[1] == L'\0');
-  ASSERT_TRUE(dest[2] == L'\0');
-  ASSERT_EQ(dest + 1, res);
-}
-
 #if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
 TEST(LlvmLibcWCPNCpyTest, NullptrCrash) {
   // Passing in a nullptr should crash the program.



More information about the libc-commits mailing list