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

Unified Diff: base/metrics/persistent_sample_map.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/persistent_sample_map.cc
diff --git a/base/metrics/persistent_sample_map.cc b/base/metrics/persistent_sample_map.cc
index dd5b8320c16dafafb49d74057883503af3e3fbaa..0b880079401946b8b867f9fa671c73ba82cf89a7 100644
--- a/base/metrics/persistent_sample_map.cc
+++ b/base/metrics/persistent_sample_map.cc
@@ -41,7 +41,7 @@ class PersistentSampleMapIterator : 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:
@@ -71,13 +71,13 @@ void PersistentSampleMapIterator::Next() {
}
void PersistentSampleMapIterator::Get(Sample* min,
- Sample* max,
+ int64_t* max,
Count* count) const {
DCHECK(!Done());
if (min)
*min = iter_->first;
if (max)
- *max = iter_->first + 1;
+ *max = static_cast<int64_t>(iter_->first) + 1;
Ilya Sherman 2017/05/02 21:37:49 nit: Here and everywhere else that you add a stati
Alexei Svitkine (slow) 2017/05/03 15:21:53 Done.
if (count)
*count = *iter_->second;
}
@@ -186,13 +186,13 @@ PersistentSampleMap::CreatePersistentRecord(
bool PersistentSampleMap::AddSubtractImpl(SampleCountIterator* iter,
Operator op) {
Sample min;
- Sample max;
+ int64_t max;
Count count;
for (; !iter->Done(); iter->Next()) {
iter->Get(&min, &max, &count);
if (count == 0)
continue;
- if (min + 1 != max)
+ if (static_cast<int64_t>(min) + 1 != max)
return false; // SparseHistogram only supports bucket with size 1.
#if 0 // TODO(bcwhite) Re-enable efficient version after crbug.com/682680.

Powered by Google App Engine
This is Rietveld 408576698