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

Unified Diff: base/metrics/histogram_samples.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/histogram_samples.h ('k') | base/metrics/persistent_sample_map.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/histogram_samples.cc
diff --git a/base/metrics/histogram_samples.cc b/base/metrics/histogram_samples.cc
index 9e86a65258d1010a5b629163f56108e6f7e0748f..59f38fc8ab5c24bcc2350b2636a97f56e5a889cf 100644
--- a/base/metrics/histogram_samples.cc
+++ b/base/metrics/histogram_samples.cc
@@ -7,6 +7,7 @@
#include <limits>
#include "base/compiler_specific.h"
+#include "base/numerics/safe_conversions.h"
#include "base/numerics/safe_math.h"
#include "base/pickle.h"
@@ -31,14 +32,14 @@ class SampleCountPickleIterator : public SampleCountIterator {
bool Done() const override;
void Next() override;
void Get(HistogramBase::Sample* min,
- HistogramBase::Sample* max,
+ int64_t* max,
HistogramBase::Count* count) const override;
private:
PickleIterator* const iter_;
HistogramBase::Sample min_;
- HistogramBase::Sample max_;
+ int64_t max_;
HistogramBase::Count count_;
bool is_done_;
};
@@ -55,14 +56,14 @@ bool SampleCountPickleIterator::Done() const {
void SampleCountPickleIterator::Next() {
DCHECK(!Done());
- if (!iter_->ReadInt(&min_) ||
- !iter_->ReadInt(&max_) ||
- !iter_->ReadInt(&count_))
+ if (!iter_->ReadInt(&min_) || !iter_->ReadInt64(&max_) ||
+ !iter_->ReadInt(&count_)) {
is_done_ = true;
+ }
}
void SampleCountPickleIterator::Get(HistogramBase::Sample* min,
- HistogramBase::Sample* max,
+ int64_t* max,
HistogramBase::Count* count) const {
DCHECK(!Done());
*min = min_;
@@ -220,15 +221,15 @@ bool HistogramSamples::Serialize(Pickle* pickle) const {
return false;
HistogramBase::Sample min;
- HistogramBase::Sample max;
+ int64_t max;
HistogramBase::Count count;
for (std::unique_ptr<SampleCountIterator> it = Iterator(); !it->Done();
it->Next()) {
it->Get(&min, &max, &count);
- if (!pickle->WriteInt(min) ||
- !pickle->WriteInt(max) ||
- !pickle->WriteInt(count))
+ if (!pickle->WriteInt(min) || !pickle->WriteInt64(max) ||
+ !pickle->WriteInt(count)) {
return false;
+ }
}
return true;
}
@@ -238,7 +239,7 @@ bool HistogramSamples::AccumulateSingleSample(HistogramBase::Sample value,
size_t bucket) {
if (single_sample().Accumulate(bucket, count)) {
// Success. Update the (separate) sum and redundant-count.
- IncreaseSumAndCount(static_cast<int64_t>(value) * count, count);
+ IncreaseSumAndCount(strict_cast<int64_t>(value) * count, count);
return true;
}
return false;
@@ -262,12 +263,12 @@ bool SampleCountIterator::GetBucketIndex(size_t* index) const {
}
SingleSampleIterator::SingleSampleIterator(HistogramBase::Sample min,
- HistogramBase::Sample max,
+ int64_t max,
HistogramBase::Count count)
: SingleSampleIterator(min, max, count, kSizeMax) {}
SingleSampleIterator::SingleSampleIterator(HistogramBase::Sample min,
- HistogramBase::Sample max,
+ int64_t max,
HistogramBase::Count count,
size_t bucket_index)
: min_(min), max_(max), bucket_index_(bucket_index), count_(count) {}
@@ -284,7 +285,7 @@ void SingleSampleIterator::Next() {
}
void SingleSampleIterator::Get(HistogramBase::Sample* min,
- HistogramBase::Sample* max,
+ int64_t* max,
HistogramBase::Count* count) const {
DCHECK(!Done());
if (min != nullptr)
« no previous file with comments | « base/metrics/histogram_samples.h ('k') | base/metrics/persistent_sample_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698