Make ThreadData::random_number_ an unsigned integer so that overflow has defined behavior.
The problem has been spotted by UBSan in base_unittests: [ RUN ] FileProxyTest.SetLength_Expand ../../base/tracked_objects.cc:457:18: runtime error: signed integer overflow: 1517486279 + 2147483647 cannot be represented in type 'int' [ OK ] FileProxyTest.SetLength_Expand (2 ms) R=jar@chromium.org TBR=darin@chromium.org BUG=none Review URL: https://codereview.chromium.org/715223002 Cr-Commit-Position: refs/heads/master@{#303893}
This commit is contained in:
@ -116,7 +116,7 @@ DeathData::DeathData(int count) {
|
||||
|
||||
void DeathData::RecordDeath(const int32 queue_duration,
|
||||
const int32 run_duration,
|
||||
int32 random_number) {
|
||||
const uint32 random_number) {
|
||||
// We'll just clamp at INT_MAX, but we should note this in the UI as such.
|
||||
if (count_ < INT_MAX)
|
||||
++count_;
|
||||
@ -307,7 +307,7 @@ void ThreadData::PushToHeadOfList() {
|
||||
(void)VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(&random_number_,
|
||||
sizeof(random_number_));
|
||||
MSAN_UNPOISON(&random_number_, sizeof(random_number_));
|
||||
random_number_ += static_cast<int32>(this - static_cast<ThreadData*>(0));
|
||||
random_number_ += static_cast<uint32>(this - static_cast<ThreadData*>(0));
|
||||
random_number_ ^= (Now() - TrackedTime()).InMilliseconds();
|
||||
|
||||
DCHECK(!next_);
|
||||
@ -453,10 +453,10 @@ void ThreadData::TallyADeath(const Births& birth,
|
||||
int32 run_duration = stopwatch.RunDurationMs();
|
||||
|
||||
// Stir in some randomness, plus add constant in case durations are zero.
|
||||
const int32 kSomePrimeNumber = 2147483647;
|
||||
const uint32 kSomePrimeNumber = 2147483647;
|
||||
random_number_ += queue_duration + run_duration + kSomePrimeNumber;
|
||||
// An address is going to have some randomness to it as well ;-).
|
||||
random_number_ ^= static_cast<int32>(&birth - reinterpret_cast<Births*>(0));
|
||||
random_number_ ^= static_cast<uint32>(&birth - reinterpret_cast<Births*>(0));
|
||||
|
||||
// We don't have queue durations without OS timer. OS timer is automatically
|
||||
// used for task-post-timing, so the use of an alternate timer implies all
|
||||
|
@ -273,7 +273,7 @@ class BASE_EXPORT DeathData {
|
||||
// |duration|, and has had a queueing delay of |queue_duration|.
|
||||
void RecordDeath(const int32 queue_duration,
|
||||
const int32 run_duration,
|
||||
int random_number);
|
||||
const uint32 random_number);
|
||||
|
||||
// Metrics accessors, used only for serialization and in tests.
|
||||
int count() const;
|
||||
@ -685,7 +685,7 @@ class BASE_EXPORT ThreadData {
|
||||
// representative sample in each DeathData instance. We can't start off with
|
||||
// much randomness (because we can't call RandInt() on all our threads), so
|
||||
// we stir in more and more as we go.
|
||||
int32 random_number_;
|
||||
uint32 random_number_;
|
||||
|
||||
// Record of what the incarnation_counter_ was when this instance was created.
|
||||
// If the incarnation_counter_ has changed, then we avoid pushing into the
|
||||
|
Reference in New Issue
Block a user