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

Kunal Dubey via libc-commits libc-commits at lists.llvm.org
Sat Nov 21 09:30:45 PST 2026


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

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.

>From a40066c5633b4c5696942d040c51ba91454a082e Mon Sep 17 00:00:00 2001
From: Kunal Dubey <xakep8 at protonmail.com>
Date: Sat, 21 Nov 2026 22:58:42 +0530
Subject: [PATCH] [libc] Fix dangling paths in line_reader_test

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.
---
 libc/test/src/__support/File/line_reader_test.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

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);



More information about the libc-commits mailing list