llvm-project
01119065 - [libc][test] Fix dangling temporary CString pointers in unit tests (#241063)

Commit
2 days ago
[libc][test] Fix dangling temporary CString pointers in unit tests (#241063) libc_make_test_file_path returns a temporary CString wrapping an owning cpp::string. Passing its implicit const char * conversion directly to TESTONLY_set_group_path (which stores the raw pointer without copying in getgrouplist_test.cpp and initgroups_test.cpp) leaves a dangling heap pointer once the full-expression ends whenever the filename exceeds cpp::string's short-string buffer. Annotate CString's pointer and string_view accessors with LIBC_LIFETIMEBOUND so Clang diagnoses temporary lifetime escapes at compile time, allow default and move construction/assignment on CString for test fixture members, and keep the CString objects alive in getgrouplist_test and initgroups_test. Assisted-by: Gemini
Author
Parents
Loading