[libc-commits] [libc] [libc] Fix dangling paths in line_reader_test (PR #244912)

via libc-commits libc-commits at lists.llvm.org
Sat Nov 21 09:31:20 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Kunal Dubey  (xakep8)

<details>
<summary>Changes</summary>

Kept the CString returned by libc_make_test_file_path alive instead of storing a pointer to its temporary string. The dangling pointers caused intermittent failures when opening the test files.

---
Full diff: https://github.com/llvm/llvm-project/pull/244912.diff


1 Files Affected:

- (modified) libc/test/src/__support/File/line_reader_test.cpp (+6-6) 


``````````diff
diff --git a/libc/test/src/__support/File/line_reader_test.cpp b/libc/test/src/__support/File/line_reader_test.cpp
index e90011acbb72e..8d79b0fc23263 100644
--- a/libc/test/src/__support/File/line_reader_test.cpp
+++ b/libc/test/src/__support/File/line_reader_test.cpp
@@ -43,7 +43,7 @@ LIBC_NAMESPACE::File *open_temp(const char *path,
 
 TEST(LlvmLibcLineReaderTest, EmptySpanAndWriteOnlyStream) {
   {
-    const char *path = libc_make_test_file_path("line_reader_empty_span.test");
+    auto path = libc_make_test_file_path("line_reader_empty_span.test");
     LIBC_NAMESPACE::File *f = open_temp(path, "\na\n");
     ASSERT_NE(f, nullptr);
     LIBC_NAMESPACE::cpp::scope_exit cleanup([&]() {
@@ -72,7 +72,7 @@ TEST(LlvmLibcLineReaderTest, EmptySpanAndWriteOnlyStream) {
   }
 
   {
-    const char *path = libc_make_test_file_path("line_reader_wonly.test");
+    auto path = libc_make_test_file_path("line_reader_wonly.test");
     LIBC_NAMESPACE::File *f = open_temp(path, "hello\n", "w");
     ASSERT_NE(f, nullptr);
     LIBC_NAMESPACE::cpp::scope_exit cleanup([&]() {
@@ -94,7 +94,7 @@ TEST(LlvmLibcLineReaderTest, EmptySpanAndWriteOnlyStream) {
 }
 
 TEST(LlvmLibcLineReaderTest, FixedSpanReadTruncateAndEof) {
-  const char *path = libc_make_test_file_path("line_reader_span.test");
+  auto path = libc_make_test_file_path("line_reader_span.test");
   LIBC_NAMESPACE::File *f = open_temp(path, "abcd\n\nefghi\nok");
   ASSERT_NE(f, nullptr);
   LIBC_NAMESPACE::cpp::scope_exit cleanup([&]() {
@@ -144,7 +144,7 @@ TEST(LlvmLibcLineReaderTest, FixedSpanReadTruncateAndEof) {
 
 TEST(LlvmLibcLineReaderTest, EmbeddedNullAndCarriageReturnPreserved) {
   constexpr char RAW[] = "ab\0cd\r\n";
-  const char *path = libc_make_test_file_path("line_reader_nul.test");
+  auto path = libc_make_test_file_path("line_reader_nul.test");
   LIBC_NAMESPACE::File *f =
       open_temp(path, LIBC_NAMESPACE::cpp::string_view(RAW, sizeof(RAW) - 1));
   ASSERT_NE(f, nullptr);
@@ -165,7 +165,7 @@ TEST(LlvmLibcLineReaderTest, DynamicBufferGrowthReuseAndEmptyEof) {
 
   // Immediate EOF on a fresh DynamicBuffer does not allocate.
   {
-    const char *empty_path = libc_make_test_file_path("line_reader_empty.test");
+    auto empty_path = libc_make_test_file_path("line_reader_empty.test");
     LIBC_NAMESPACE::File *empty_f = open_temp(empty_path, "");
     ASSERT_NE(empty_f, nullptr);
     LIBC_NAMESPACE::cpp::scope_exit cleanup_empty([&]() {
@@ -187,7 +187,7 @@ TEST(LlvmLibcLineReaderTest, DynamicBufferGrowthReuseAndEmptyEof) {
   content[LONG_LEN + 1] = 'h';
   content[LONG_LEN + 2] = 'i';
 
-  const char *long_path = libc_make_test_file_path("line_reader_long.test");
+  auto long_path = libc_make_test_file_path("line_reader_long.test");
   LIBC_NAMESPACE::File *long_f = open_temp(
       long_path, LIBC_NAMESPACE::cpp::string_view(content, LONG_LEN + 3));
   ASSERT_NE(long_f, nullptr);

``````````

</details>


https://github.com/llvm/llvm-project/pull/244912


More information about the libc-commits mailing list