This commit is contained in:
Sergey 2025-02-07 02:15:43 +00:00 committed by GitHub
commit 18f0b7403c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -109,7 +109,10 @@ FilePath FilePath::GetCurrentDir() {
return FilePath(kCurrentDirectoryString);
#elif defined(GTEST_OS_WINDOWS)
char cwd[GTEST_PATH_MAX_ + 1] = {'\0'};
return FilePath(_getcwd(cwd, sizeof(cwd)) == nullptr ? "" : cwd);
if (_getcwd(cwd, sizeof(cwd)) == nullptr) return {};
auto len = std::strlen(cwd);
if (len > 0 && cwd[len - 1] == '\\') cwd[--len] = 0;
return FilePath({cwd, len});
#else
char cwd[GTEST_PATH_MAX_ + 1] = {'\0'};
char* result = getcwd(cwd, sizeof(cwd));