[libc-commits] [libc] [libc] Implemented wmempcpy (PR #142067)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Fri May 30 10:42:48 PDT 2025
================
@@ -0,0 +1,44 @@
+//===-- Unittests for wmempcpy --------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/wchar/wmempcpy.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcWMempcpyTest, Simple) {
+ const wchar_t *src = L"12345";
+ wchar_t dest[10] = {};
+ void *result = LIBC_NAMESPACE::wmempcpy(dest, src, 6);
+ ASSERT_EQ(static_cast<wchar_t *>(result), dest + 6);
+
+ ASSERT_TRUE(src[0] == dest[0]);
+ ASSERT_TRUE(src[1] == dest[1]);
+ ASSERT_TRUE(src[2] == dest[2]);
+ ASSERT_TRUE(src[3] == dest[3]);
+ ASSERT_TRUE(src[4] == dest[4]);
+ ASSERT_TRUE(src[5] == dest[5]);
+}
+
+TEST(LlvmLibcWmempcpyTest, ZeroCount) {
+ const wchar_t *src = L"12345";
+ wchar_t dest[10];
+ void *result = LIBC_NAMESPACE::wmempcpy(dest, src, 0);
+ ASSERT_EQ(static_cast<wchar_t *>(result), dest);
+}
+
+TEST(LlvmLibcWMempcpyTest, BoundaryCheck) {
+ const wchar_t *src = L"12345";
+ wchar_t dest[4] = {};
----------------
michaelrj-google wrote:
since you're assuming the values in dest will be zero it's important to explicitly initialize them to zero.
```suggestion
wchar_t dest[4] = {0, 0, 0, 0};
```
https://github.com/llvm/llvm-project/pull/142067
More information about the libc-commits
mailing list