diff --git a/googlemock/include/gmock/gmock-more-matchers.h b/googlemock/include/gmock/gmock-more-matchers.h index d29123a67..9d9688ef0 100644 --- a/googlemock/include/gmock/gmock-more-matchers.h +++ b/googlemock/include/gmock/gmock-more-matchers.h @@ -76,12 +76,18 @@ class [[nodiscard]] IsEmptyMatcher { // Matches C-style strings. bool MatchAndExplain(const char* s, MatchResultListener* listener) const { + if (s == nullptr) { + return false; + } return MatchAndExplain(std::string(s), listener); } #if GTEST_HAS_STD_WSTRING // Matches C-style wide strings. bool MatchAndExplain(const wchar_t* s, MatchResultListener* listener) const { + if (s == nullptr) { + return false; + } return MatchAndExplain(std::wstring(s), listener); } #endif // GTEST_HAS_STD_WSTRING diff --git a/googlemock/test/gmock-matchers-comparisons_test.cc b/googlemock/test/gmock-matchers-comparisons_test.cc index 8a9981fcd..b800f1e8b 100644 --- a/googlemock/test/gmock-matchers-comparisons_test.cc +++ b/googlemock/test/gmock-matchers-comparisons_test.cc @@ -1092,6 +1092,7 @@ TEST(IsEmptyTest, MatchesCString) { const char b[] = "x"; EXPECT_TRUE(m.Matches(a)); EXPECT_FALSE(m.Matches(b)); + EXPECT_FALSE(m.Matches(nullptr)); } #if GTEST_HAS_STD_WSTRING @@ -1101,6 +1102,7 @@ TEST(IsEmptyTest, MatchesCWideString) { const wchar_t b[] = L"x"; EXPECT_TRUE(m.Matches(a)); EXPECT_FALSE(m.Matches(b)); + EXPECT_FALSE(m.Matches(nullptr)); } #endif // GTEST_HAS_STD_WSTRING