diff options
author | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-19 18:48:16 +0000 |
---|---|---|
committer | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-19 18:48:16 +0000 |
commit | a75cc1ba7c30e4064ea4786fc5147c84e5b390aa (patch) | |
tree | 9152f62ef6730b7fbb09251a44aaa1dc1271d80c | |
parent | 2b67f93ce2bccaa23e363efa949839e631e070cd (diff) | |
download | chromium_src-a75cc1ba7c30e4064ea4786fc5147c84e5b390aa.zip chromium_src-a75cc1ba7c30e4064ea4786fc5147c84e5b390aa.tar.gz chromium_src-a75cc1ba7c30e4064ea4786fc5147c84e5b390aa.tar.bz2 |
Make 64-bit constants 64-bit.
Otherwise, shifting beyond 32-bits doesn't work, leading to failures in the
auto-enrollment protocol.
Introduced a new unit_tests that fails before this fix.
BUG=110718
TEST=AutoEnrollmentClientTest.* pass
Review URL: http://codereview.chromium.org/9195011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118327 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/policy/auto_enrollment_client.cc | 10 | ||||
-rw-r--r-- | chrome/browser/policy/auto_enrollment_client_unittest.cc | 16 |
2 files changed, 18 insertions, 8 deletions
diff --git a/chrome/browser/policy/auto_enrollment_client.cc b/chrome/browser/policy/auto_enrollment_client.cc index 7d8ebef..ec5bf14 100644 --- a/chrome/browser/policy/auto_enrollment_client.cc +++ b/chrome/browser/policy/auto_enrollment_client.cc @@ -52,7 +52,7 @@ int GetSanitizedArg(const std::string& switch_name) { // Returns the power of the next power-of-2 starting at |value|. int NextPowerOf2(int64 value) { for (int i = 0; i <= kMaximumPower; ++i) { - if ((1 << i) >= value) + if ((GG_INT64_C(1) << i) >= value) return i; } // No other value can be represented in an int64. @@ -160,7 +160,7 @@ void AutoEnrollmentClient::SendRequest(int power) { uint64 byte = serial_number_hash_[31 - i] & 0xff; remainder = remainder | (byte << (8 * i)); } - remainder = remainder & ((1ULL << power) - 1); + remainder = remainder & ((GG_UINT64_C(1) << power) - 1); request_job_.reset( device_management_service_->CreateJob( @@ -169,7 +169,7 @@ void AutoEnrollmentClient::SendRequest(int power) { em::DeviceAutoEnrollmentRequest* request = request_job_->GetRequest()->mutable_auto_enrollment_request(); request->set_remainder(remainder); - request->set_modulus((int64) 1 << power); + request->set_modulus(GG_INT64_C(1) << power); request_job_->Start(base::Bind(&AutoEnrollmentClient::OnRequestCompletion, base::Unretained(this))); } @@ -188,9 +188,9 @@ void AutoEnrollmentClient::OnRequestCompletion( if (enrollment_response.has_expected_modulus()) { // Server is asking us to retry with a different modulus. int64 modulus = enrollment_response.expected_modulus(); - int64 last_modulus_used = 1 << last_power_used_; + int64 last_modulus_used = GG_INT64_C(1) << last_power_used_; int power = NextPowerOf2(modulus); - if ((1 << power) != modulus) { + if ((GG_INT64_C(1) << power) != modulus) { LOG(WARNING) << "Auto enrollment: the server didn't ask for a power-of-2 " << "modulus. Using the closest power-of-2 instead " << "(" << modulus << " vs 2^" << power << ")"; diff --git a/chrome/browser/policy/auto_enrollment_client_unittest.cc b/chrome/browser/policy/auto_enrollment_client_unittest.cc index 77a6235e..c37838a 100644 --- a/chrome/browser/policy/auto_enrollment_client_unittest.cc +++ b/chrome/browser/policy/auto_enrollment_client_unittest.cc @@ -211,7 +211,7 @@ TEST_F(AutoEnrollmentClientTest, NoBitsUploaded) { } TEST_F(AutoEnrollmentClientTest, ManyBitsUploaded) { - int64 bottom62 = GG_LONGLONG(0x14e437a1552b138a); + int64 bottom62 = GG_INT64_C(0x14e437a1552b138a); for (int i = 0; i <= 62; ++i) { completion_callback_count_ = 0; CreateClient(kSerial, i, i); @@ -221,11 +221,21 @@ TEST_F(AutoEnrollmentClientTest, ManyBitsUploaded) { EXPECT_EQ(1, completion_callback_count_); EXPECT_TRUE(last_request_.has_remainder()); EXPECT_TRUE(last_request_.has_modulus()); - EXPECT_EQ((int64) 1 << i, last_request_.modulus()); - EXPECT_EQ(bottom62 % ((int64) 1 << i), last_request_.remainder()); + EXPECT_EQ(GG_INT64_C(1) << i, last_request_.modulus()); + EXPECT_EQ(bottom62 % (GG_INT64_C(1) << i), last_request_.remainder()); } } +TEST_F(AutoEnrollmentClientTest, MoreThan32BitsUploaded) { + CreateClient(kSerial, 10, 37); + InSequence sequence; + ServerWillReply(GG_INT64_C(1) << 37, false, false); + ServerWillReply(-1, true, true); + client_->Start(); + EXPECT_TRUE(client_->should_auto_enroll()); + EXPECT_EQ(1, completion_callback_count_); +} + } // namespace } // namespace policy |