Skip to content

Commit e77001c

Browse files
[libc] Use a sensible default when TEST_UNDECLARED_OUTPUTS_DIR is unset. (llvm#167422)
There is no guarantee that this environment variable is set. Eg, when running a test outside of the build system, such as under a debugger. And passing a nullptr to the string constructor is undefined. Use an empty string, which seems like it is close to the original intent.
1 parent 9fce004 commit e77001c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

libc/test/UnitTest/BazelFilePath.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ namespace testing {
2020
CString libc_make_test_file_path_func(const char *file_name) {
2121
// This is the path to the folder bazel wants the test outputs written to.
2222
const char *UNDECLARED_OUTPUTS_PATH = getenv("TEST_UNDECLARED_OUTPUTS_DIR");
23+
// Do something sensible if not run under bazel, otherwise this may segfault
24+
// when constructing the string.
25+
if (UNDECLARED_OUTPUTS_PATH == nullptr)
26+
UNDECLARED_OUTPUTS_PATH = "";
2327

2428
return cpp::string(UNDECLARED_OUTPUTS_PATH) + file_name;
2529
}

0 commit comments

Comments
 (0)