-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Fix readlink tests on 32-bit systems #97850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-libc Author: Mikhail R. Gadelha (mikhailramalho) ChangesUse 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. Full diff: https://github.com/llvm/llvm-project/pull/97850.diff 3 Files Affected:
diff --git a/libc/test/src/unistd/CMakeLists.txt b/libc/test/src/unistd/CMakeLists.txt
index de3e8d9ccbb626..b311bbf59bbca2 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.strlen
libc.src.unistd.symlink
libc.src.unistd.unlink
libc.src.__support.CPP.string_view
@@ -279,6 +280,7 @@ add_libc_unittest(
libc.include.unistd
libc.src.errno.errno
libc.src.unistd.readlinkat
+ libc.src.string.strlen
libc.src.unistd.symlink
libc.src.unistd.unlink
libc.src.__support.CPP.string_view
diff --git a/libc/test/src/unistd/readlink_test.cpp b/libc/test/src/unistd/readlink_test.cpp
index 20f3951349118a..cd2a36ed86b11d 100644
--- a/libc/test/src/unistd/readlink_test.cpp
+++ b/libc/test/src/unistd/readlink_test.cpp
@@ -8,6 +8,7 @@
#include "src/__support/CPP/string_view.h"
#include "src/errno/libc_errno.h"
+#include "src/string/strlen.h"
#include "src/unistd/readlink.h"
#include "src/unistd/symlink.h"
#include "src/unistd/unlink.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::strlen(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 39d81d9ba544a6..33c6c8968b1438 100644
--- a/libc/test/src/unistd/readlinkat_test.cpp
+++ b/libc/test/src/unistd/readlinkat_test.cpp
@@ -8,6 +8,7 @@
#include "src/__support/CPP/string_view.h"
#include "src/errno/libc_errno.h"
+#include "src/string/strlen.h"
#include "src/unistd/readlinkat.h"
#include "src/unistd/symlink.h"
#include "src/unistd/unlink.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::strlen(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));
}
|
66113a1
to
39c9793
Compare
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.
39c9793
to
e28df25
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/43/builds/1493 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/171/builds/1485 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/131/builds/1494 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/147/builds/1446 Here is the relevant piece of the build log for the reference:
|
This reverts commit 0f1da49.
Reverts #97850 while I investigate the buildbot issue
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.
Reverts llvm#97850 while I investigate the buildbot issue
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.