[libc-commits] [PATCH] D125917: [libc][windows] fix strlcpy tests

Michael Jones via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed May 18 11:45:19 PDT 2022

michaelrj created this revision.
michaelrj added a reviewer: abrachet.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added projects: libc-project, All.
michaelrj requested review of this revision.

Generally, size_t is an alias for unsigned long long. In the strlcpy
tests, the return value of strlcpy (a size_t) is compared to an unsigned
long. On Linux unsigned long and unsigned long long are both 64 bits,
but on windows unsigned long is 32 bits. Since the macros require
identical types for both sides, this caused a build failure on windows.
This patch changes the constants to be explicit size_t values.

  rG LLVM Github Monorepo



Index: libc/test/src/string/strlcpy_test.cpp
--- libc/test/src/string/strlcpy_test.cpp
+++ libc/test/src/string/strlcpy_test.cpp
@@ -13,17 +13,17 @@
 TEST(LlvmLibcStrlcpyTest, TooBig) {
   const char *str = "abc";
   char buf[2];
-  EXPECT_EQ(__llvm_libc::strlcpy(buf, str, 2), 3ul);
+  EXPECT_EQ(__llvm_libc::strlcpy(buf, str, 2), size_t(3));
   EXPECT_STREQ(buf, "a");
-  EXPECT_EQ(__llvm_libc::strlcpy(nullptr, str, 0), 3ul);
+  EXPECT_EQ(__llvm_libc::strlcpy(nullptr, str, 0), size_t(3));
 TEST(LlvmLibcStrlcpyTest, Smaller) {
   const char *str = "abc";
   char buf[7]{"111111"};
-  EXPECT_EQ(__llvm_libc::strlcpy(buf, str, 7), 3ul);
+  EXPECT_EQ(__llvm_libc::strlcpy(buf, str, 7), size_t(3));
   EXPECT_STREQ(buf, "abc");
   for (const char *p = buf + 3; p < buf + 7; p++)
     EXPECT_EQ(*p, '\0');

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125917.430470.patch
Type: text/x-patch
Size: 882 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20220518/09352285/attachment-0001.bin>

More information about the libc-commits mailing list