diff options
author | Gennadiy Civil <misterg@google.com> | 2019-04-18 13:44:23 (GMT) |
---|---|---|
committer | Gennadiy Civil <misterg@google.com> | 2019-04-18 13:44:24 (GMT) |
commit | a0d60bed4d0ea17c7130cda16776b9bc8a929d7b (patch) | |
tree | b04bb7a474c3b1b61e23896402b4510307657812 /googletest/src/gtest-internal-inl.h | |
parent | 9f893b99598b1f0725dc8b92037f0d9f53095b90 (diff) | |
parent | 3829b84e9927a2a77a7634a8e7b010cc57095e1b (diff) | |
download | googletest-a0d60bed4d0ea17c7130cda16776b9bc8a929d7b.zip googletest-a0d60bed4d0ea17c7130cda16776b9bc8a929d7b.tar.gz googletest-a0d60bed4d0ea17c7130cda16776b9bc8a929d7b.tar.bz2 |
Merge pull request #2170 from ngie-eign:issue-2146-ver2
PiperOrigin-RevId: 244069956
Diffstat (limited to 'googletest/src/gtest-internal-inl.h')
-rw-r--r-- | googletest/src/gtest-internal-inl.h | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h index 29dc682..53cd22b 100644 --- a/googletest/src/gtest-internal-inl.h +++ b/googletest/src/gtest-internal-inl.h @@ -298,7 +298,8 @@ void ForEach(const Container& c, Functor functor) { // in range [0, v.size()). template <typename E> inline E GetElementOr(const std::vector<E>& v, int i, E default_value) { - return (i < 0 || i >= static_cast<int>(v.size())) ? default_value : v[i]; + return (i < 0 || i >= static_cast<int>(v.size())) ? default_value + : v[static_cast<size_t>(i)]; } // Performs an in-place shuffle of a range of the vector's elements. @@ -320,8 +321,11 @@ void ShuffleRange(internal::Random* random, int begin, int end, // http://en.wikipedia.org/wiki/Fisher-Yates_shuffle for (int range_width = end - begin; range_width >= 2; range_width--) { const int last_in_range = begin + range_width - 1; - const int selected = begin + random->Generate(range_width); - std::swap((*v)[selected], (*v)[last_in_range]); + const int selected = + begin + + static_cast<int>(random->Generate(static_cast<UInt32>(range_width))); + std::swap((*v)[static_cast<size_t>(selected)], + (*v)[static_cast<size_t>(last_in_range)]); } } @@ -586,7 +590,7 @@ class GTEST_API_ UnitTestImpl { // total_test_suite_count() - 1. If i is not in that range, returns NULL. const TestSuite* GetTestSuite(int i) const { const int index = GetElementOr(test_suite_indices_, i, -1); - return index < 0 ? nullptr : test_suites_[i]; + return index < 0 ? nullptr : test_suites_[static_cast<size_t>(i)]; } // Legacy API is deprecated but still available @@ -598,7 +602,7 @@ class GTEST_API_ UnitTestImpl { // total_test_suite_count() - 1. If i is not in that range, returns NULL. TestSuite* GetMutableSuiteCase(int i) { const int index = GetElementOr(test_suite_indices_, i, -1); - return index < 0 ? nullptr : test_suites_[index]; + return index < 0 ? nullptr : test_suites_[static_cast<size_t>(index)]; } // Provides access to the event listener list. @@ -1083,8 +1087,8 @@ class StreamingListener : public EmptyTestEventListener { GTEST_CHECK_(sockfd_ != -1) << "Send() can be called only when there is a connection."; - const int len = static_cast<int>(message.length()); - if (write(sockfd_, message.c_str(), len) != len) { + const auto len = static_cast<size_t>(message.length()); + if (write(sockfd_, message.c_str(), len) != static_cast<ssize_t>(len)) { GTEST_LOG_(WARNING) << "stream_result_to: failed to stream to " << host_name_ << ":" << port_num_; |