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

Unified Diff: base/metrics/histogram_samples.cc

Issue 2853853002: Fix overflow when logging MaxInt32 to a sparse histogram. (Closed)
Patch Set: 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
Index: base/metrics/histogram_samples.cc
diff --git a/base/metrics/histogram_samples.cc b/base/metrics/histogram_samples.cc
index 9e86a65258d1010a5b629163f56108e6f7e0748f..e7e0193677892c7b3c2ee7e027dcdc87ded7262f 100644
--- a/base/metrics/histogram_samples.cc
+++ b/base/metrics/histogram_samples.cc
@@ -31,14 +31,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 +55,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 +220,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;
}
@@ -262,12 +262,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 +284,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)

Powered by Google App Engine
This is Rietveld 408576698