Skip to content

Commit

Permalink
Googletest export
Browse files Browse the repository at this point in the history
Add a safety nullptr check to catch the case where the /tmp file used for capturing a stream cannot be created.

PiperOrigin-RevId: 250523012
  • Loading branch information
Abseil Team authored and gennadiycivil committed May 30, 2019
1 parent f5edb4f commit 899c082
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ instructions for how to sign and return it. Once we receive it, we'll be able to
accept your pull requests.

## Are you a Googler?
If you are a Googler, plese make an attempt to submit an internal change rather than a GitHub Pull Request.
If you are not able to submit an internal change a PR is acceptable as an alternative.
If you are a Googler, you can either create an internal change or work on GitHub directly.


## Contributing A Patch
Expand Down
9 changes: 9 additions & 0 deletions googletest/src/gtest-port.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,11 @@ class CapturedStream {
char name_template[] = "/tmp/captured_stream.XXXXXX";
# endif // GTEST_OS_LINUX_ANDROID
const int captured_fd = mkstemp(name_template);
if (captured_fd == -1) {
GTEST_LOG_(WARNING)
<< "Failed to create tmp file " << name_template
<< " for test; does the test have access to the /tmp directory?";
}
filename_ = name_template;
# endif // GTEST_OS_WINDOWS
fflush(nullptr);
Expand All @@ -1134,6 +1139,10 @@ class CapturedStream {
}

FILE* const file = posix::FOpen(filename_.c_str(), "r");
if (file == nullptr) {
GTEST_LOG_(FATAL) << "Failed to open tmp file " << filename_
<< " for capturing stream.";
}
const std::string content = ReadEntireFile(file);
posix::FClose(file);
return content;
Expand Down

0 comments on commit 899c082

Please sign in to comment.
  NODES
COMMUNITY 1
INTERN 3
Note 1
Project 1
USERS 1