diff options
author | Mikhail R. Gadelha <mikhail@igalia.com> | 2024-07-05 20:20:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-05 15:20:51 -0300 |
commit | 0f1da49b4d854ce7c6572000da3fb6cb0a1245d2 (patch) | |
tree | ee00e080d217ec51feb54018a30e547358474244 | |
parent | 23d1d959583c35e6eab7e3e70d4c16449b418563 (diff) | |
download | llvm-0f1da49b4d854ce7c6572000da3fb6cb0a1245d2.zip llvm-0f1da49b4d854ce7c6572000da3fb6cb0a1245d2.tar.gz llvm-0f1da49b4d854ce7c6572000da3fb6cb0a1245d2.tar.bz2 |
[libc] Fix readlink tests on 32-bit systems (#97850)
Use sizeof in a string literal instead of a CString so we get the right size when creating the buf array.
We also now use strlen(FILENAME) to get the string lenght when calling readlink and readlinkat.
-rw-r--r-- | libc/test/src/unistd/CMakeLists.txt | 2 | ||||
-rw-r--r-- | libc/test/src/unistd/readlink_test.cpp | 11 | ||||
-rw-r--r-- | libc/test/src/unistd/readlinkat_test.cpp | 15 |
3 files changed, 18 insertions, 10 deletions
diff --git a/libc/test/src/unistd/CMakeLists.txt b/libc/test/src/unistd/CMakeLists.txt index de3e8d9c..f4f78b8 100644 --- a/libc/test/src/unistd/CMakeLists.txt +++ b/libc/test/src/unistd/CMakeLists.txt @@ -262,6 +262,7 @@ add_libc_unittest( libc.include.unistd libc.src.errno.errno libc.src.unistd.readlink + libc.src.string.string_utils libc.src.unistd.symlink libc.src.unistd.unlink libc.src.__support.CPP.string_view @@ -278,6 +279,7 @@ add_libc_unittest( libc.include.fcntl libc.include.unistd libc.src.errno.errno + libc.src.string.string_utils libc.src.unistd.readlinkat libc.src.unistd.symlink libc.src.unistd.unlink diff --git a/libc/test/src/unistd/readlink_test.cpp b/libc/test/src/unistd/readlink_test.cpp index 20f3951..0760850 100644 --- a/libc/test/src/unistd/readlink_test.cpp +++ b/libc/test/src/unistd/readlink_test.cpp @@ -9,6 +9,7 @@ #include "src/__support/CPP/string_view.h" #include "src/errno/libc_errno.h" #include "src/unistd/readlink.h" +#include "src/string/string_utils.h" #include "src/unistd/symlink.h" #include "src/unistd/unlink.h" #include "test/UnitTest/ErrnoSetterMatcher.h" @@ -30,8 +31,9 @@ TEST(LlvmLibcReadlinkTest, CreateAndUnlink) { // 3. Cleanup the symlink created in step #1. ASSERT_THAT(LIBC_NAMESPACE::symlink(LINK_VAL, LINK), Succeeds(0)); - char buf[sizeof(LINK_VAL)]; - ssize_t len = LIBC_NAMESPACE::readlink(LINK, buf, sizeof(buf)); + char buf[sizeof(FILENAME)]; + ssize_t len = LIBC_NAMESPACE::readlink( + LINK, buf, LIBC_NAMESPACE::internal::string_length(FILENAME)); ASSERT_ERRNO_SUCCESS(); ASSERT_EQ(cpp::string_view(buf, len), cpp::string_view(LINK_VAL)); @@ -40,7 +42,8 @@ TEST(LlvmLibcReadlinkTest, CreateAndUnlink) { TEST(LlvmLibcReadlinkTest, ReadlinkInNonExistentPath) { using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; - char buf[8]; - ASSERT_THAT(LIBC_NAMESPACE::readlink("non-existent-link", buf, sizeof(buf)), + constexpr auto len = 8; + char buf[len]; + ASSERT_THAT(LIBC_NAMESPACE::readlink("non-existent-link", buf, len), Fails(ENOENT)); } diff --git a/libc/test/src/unistd/readlinkat_test.cpp b/libc/test/src/unistd/readlinkat_test.cpp index 39d81d9..61e8773 100644 --- a/libc/test/src/unistd/readlinkat_test.cpp +++ b/libc/test/src/unistd/readlinkat_test.cpp @@ -9,6 +9,7 @@ #include "src/__support/CPP/string_view.h" #include "src/errno/libc_errno.h" #include "src/unistd/readlinkat.h" +#include "src/string/string_utils.h" #include "src/unistd/symlink.h" #include "src/unistd/unlink.h" #include "test/UnitTest/ErrnoSetterMatcher.h" @@ -32,8 +33,9 @@ TEST(LlvmLibcReadlinkatTest, CreateAndUnlink) { // 3. Cleanup the symlink created in step #1. ASSERT_THAT(LIBC_NAMESPACE::symlink(LINK_VAL, LINK), Succeeds(0)); - char buf[sizeof(LINK_VAL)]; - ssize_t len = LIBC_NAMESPACE::readlinkat(AT_FDCWD, LINK, buf, sizeof(buf)); + char buf[sizeof(FILENAME)]; + ssize_t len = LIBC_NAMESPACE::readlinkat( + AT_FDCWD, LINK, buf, LIBC_NAMESPACE::internal::string_length(FILENAME)); ASSERT_ERRNO_SUCCESS(); ASSERT_EQ(cpp::string_view(buf, len), cpp::string_view(LINK_VAL)); @@ -42,8 +44,9 @@ TEST(LlvmLibcReadlinkatTest, CreateAndUnlink) { TEST(LlvmLibcReadlinkatTest, ReadlinkInNonExistentPath) { using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; - char buf[8]; - ASSERT_THAT(LIBC_NAMESPACE::readlinkat(AT_FDCWD, "non-existent-link", buf, - sizeof(buf)), - Fails(ENOENT)); + constexpr auto len = 8; + char buf[len]; + ASSERT_THAT( + LIBC_NAMESPACE::readlinkat(AT_FDCWD, "non-existent-link", buf, len), + Fails(ENOENT)); } |