summaryrefslogtreecommitdiff
path: root/libc/test/UnitTest/BazelFilePath.cpp
diff options
context:
space:
mode:
authorSterling-Augustine <saugustine@google.com>2025-11-11 11:49:10 -0800
committerGitHub <noreply@github.com>2025-11-11 11:49:10 -0800
commite77001c9f5b5e99d915a2f45f9f067e83def22e1 (patch)
treea97ea4a9c9dc674dfae515524143f19bb638c2a3 /libc/test/UnitTest/BazelFilePath.cpp
parent9fce00469d03d7bf9acbbcd6597206cbbbbbe238 (diff)
[libc] Use a sensible default when TEST_UNDECLARED_OUTPUTS_DIR is unset. (#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.
Diffstat (limited to 'libc/test/UnitTest/BazelFilePath.cpp')
-rw-r--r--libc/test/UnitTest/BazelFilePath.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/libc/test/UnitTest/BazelFilePath.cpp b/libc/test/UnitTest/BazelFilePath.cpp
index ee5fcaaa63d9..7f9f42b46dca 100644
--- a/libc/test/UnitTest/BazelFilePath.cpp
+++ b/libc/test/UnitTest/BazelFilePath.cpp
@@ -20,6 +20,10 @@ namespace testing {
CString libc_make_test_file_path_func(const char *file_name) {
// This is the path to the folder bazel wants the test outputs written to.
const char *UNDECLARED_OUTPUTS_PATH = getenv("TEST_UNDECLARED_OUTPUTS_DIR");
+ // Do something sensible if not run under bazel, otherwise this may segfault
+ // when constructing the string.
+ if (UNDECLARED_OUTPUTS_PATH == nullptr)
+ UNDECLARED_OUTPUTS_PATH = "";
return cpp::string(UNDECLARED_OUTPUTS_PATH) + file_name;
}