From deb99a9d268b7846cace92386414cd799002f855 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 11 Apr 2017 10:20:18 -0700 Subject: [PATCH] Use wider types to prevent unsigned overflow diagnostics The rest of the (covered) codebase is already integer overflow clean. This is a cherry-pick of an internal change. TESTED=gtest_shuffle_test goes from fail to pass with -fsanitize=integer --- googletest/src/gtest.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 4aed0e1c..6cac93d5 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -310,7 +310,8 @@ namespace internal { // than kMaxRange. UInt32 Random::Generate(UInt32 range) { // These constants are the same as are used in glibc's rand(3). - state_ = (1103515245U*state_ + 12345U) % kMaxRange; + // Use wider types than necessary to prevent unsigned overflow diagnostics. + state_ = static_cast(1103515245ULL*state_ + 12345U) % kMaxRange; GTEST_CHECK_(range > 0) << "Cannot generate a number in the range [0, 0).";