[libc-commits] [libc] [libc][test] Fix dangling CString paths in copy_file_range_test (PR #241787)
via libc-commits
libc-commits at lists.llvm.org
Thu Nov 12 02:57:39 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Aman Maurya (amanmaurya92)
<details>
<summary>Changes</summary>
Fixes the `aarch64` / overlay failure in `libc.test.src.unistd.copy_file_range_test` introduced by #<!-- -->240018.
### Root Cause
1. `libc_make_test_file_path(...)` returns an owning `CString` (non-copyable, non-movable). Storing it into `const char *in_path` / `out_path` in `SetUp()` destroyed the temporary `CString` immediately, leaving dangling pointers for `open()` and `unlink()` and causing `ENOENT` in `SetUp()` (cascading into `EBADF` in `CopyNoOffsets` and `CopyWithOffsets`).
2. `LlvmLibcCopyFileRangeTest::SetUp()` and `TearDown()` overrode `ErrnoCheckingTest::SetUp()` / `TearDown()` without invoking the base class methods.
### Changes
- Initialize `in_path` and `out_path` directly as fixture members using `decltype(libc_make_test_file_path(...))` so the `CString` objects stay alive for the full test lifetime.
- Call `ErrnoCheckingTest::SetUp()` at the start of `SetUp()` and `ErrnoCheckingTest::TearDown()` at the end of `TearDown()`.
### Testing
- Verified `clang-format --dry-run --Werror` on `libc/test/src/unistd/copy_file_range_test.cpp`.
- Built and ran `copy_file_range_test` locally (`Ran 3 tests. PASS: 3 FAIL: 0`).
---
Full diff: https://github.com/llvm/llvm-project/pull/241787.diff
1 Files Affected:
- (modified) libc/test/src/unistd/copy_file_range_test.cpp (+8-8)
``````````diff
diff --git a/libc/test/src/unistd/copy_file_range_test.cpp b/libc/test/src/unistd/copy_file_range_test.cpp
index 67959d3d31d4f..87cc46373084a 100644
--- a/libc/test/src/unistd/copy_file_range_test.cpp
+++ b/libc/test/src/unistd/copy_file_range_test.cpp
@@ -35,14 +35,15 @@ class LlvmLibcCopyFileRangeTest
static constexpr const char TEST_DATA[] = "0123456789ABCDEF";
static constexpr size_t TEST_SIZE = sizeof(TEST_DATA) - 1;
- const char *in_path = nullptr;
- const char *out_path = nullptr;
+ decltype(libc_make_test_file_path(IN_FILENAME)) in_path =
+ libc_make_test_file_path(IN_FILENAME);
+ decltype(libc_make_test_file_path(OUT_FILENAME)) out_path =
+ libc_make_test_file_path(OUT_FILENAME);
int in_fd = -1;
int out_fd = -1;
void SetUp() override {
- in_path = libc_make_test_file_path(IN_FILENAME);
- out_path = libc_make_test_file_path(OUT_FILENAME);
+ ErrnoCheckingTest::SetUp();
int write_fd =
LIBC_NAMESPACE::open(in_path, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU);
@@ -71,10 +72,9 @@ class LlvmLibcCopyFileRangeTest
LIBC_NAMESPACE::close(out_fd);
out_fd = -1;
}
- if (in_path)
- LIBC_NAMESPACE::unlink(in_path);
- if (out_path)
- LIBC_NAMESPACE::unlink(out_path);
+ LIBC_NAMESPACE::unlink(in_path);
+ LIBC_NAMESPACE::unlink(out_path);
+ ErrnoCheckingTest::TearDown();
}
};
``````````
</details>
https://github.com/llvm/llvm-project/pull/241787
More information about the libc-commits
mailing list