Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(859)

Unified Diff: base/metrics/sample_vector.cc

Issue 2853853002: Fix overflow when logging MaxInt32 to a sparse histogram. (Closed)
Patch Set: Address comments. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/metrics/sample_vector.h ('k') | base/metrics/sample_vector_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/sample_vector.cc
diff --git a/base/metrics/sample_vector.cc b/base/metrics/sample_vector.cc
index b55449d245be4089b39973c2f3c12414865433ad..219ab712de1aea46500fba45d907763fca0cb52a 100644
--- a/base/metrics/sample_vector.cc
+++ b/base/metrics/sample_vector.cc
@@ -8,6 +8,7 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/persistent_memory_allocator.h"
+#include "base/numerics/safe_conversions.h"
#include "base/synchronization/lock.h"
#include "base/threading/platform_thread.h"
@@ -61,7 +62,7 @@ void SampleVectorBase::Accumulate(Sample value, Count count) {
// Handle the multi-sample case.
subtle::NoBarrier_AtomicIncrement(&counts()[bucket_index], count);
- IncreaseSumAndCount(static_cast<int64_t>(count) * value, count);
+ IncreaseSumAndCount(strict_cast<int64_t>(count) * value, count);
}
Count SampleVectorBase::GetCount(Sample value) const {
@@ -132,7 +133,7 @@ bool SampleVectorBase::AddSubtractImpl(SampleCountIterator* iter,
// Get the first value and its index.
HistogramBase::Sample min;
- HistogramBase::Sample max;
+ int64_t max;
HistogramBase::Count count;
iter->Get(&min, &max, &count);
size_t dest_index = GetBucketIndex(min);
@@ -392,13 +393,13 @@ void SampleVectorIterator::Next() {
}
void SampleVectorIterator::Get(HistogramBase::Sample* min,
- HistogramBase::Sample* max,
+ int64_t* max,
HistogramBase::Count* count) const {
DCHECK(!Done());
if (min != NULL)
*min = bucket_ranges_->range(index_);
if (max != NULL)
- *max = bucket_ranges_->range(index_ + 1);
+ *max = strict_cast<int64_t>(bucket_ranges_->range(index_ + 1));
if (count != NULL)
*count = subtle::NoBarrier_Load(&counts_[index_]);
}
« no previous file with comments | « base/metrics/sample_vector.h ('k') | base/metrics/sample_vector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698