From 88f6706e9966f83f8bc74b3433a5acd732262461 Mon Sep 17 00:00:00 2001 From: Tobias Markus Date: Tue, 14 May 2024 08:15:09 +0200 Subject: [PATCH] Check for str being a null pointer before parsing string as an int32 --- googletest/src/gtest-port.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index 1038ad7bf..572db6103 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -1322,6 +1322,15 @@ static std::string FlagToEnvVar(const char* flag) { // the result to *value and returns true; otherwise leaves *value // unchanged and returns false. bool ParseInt32(const Message& src_text, const char* str, int32_t* value) { + if (str == nullptr) { + Message msg; + msg << "WARNING: " << src_text + << " is NULL and can not be parsed for a 32-bit signed integer"; + printf("%s", msg.GetString().c_str()); + fflush(stdout); + return false; + } + // Parses the environment variable as a decimal integer. char* end = nullptr; const long long_value = strtol(str, &end, 10); // NOLINT